Skip to content

Commit

Permalink
add health endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
blesswinsamuel committed Sep 20, 2023
1 parent 77fde81 commit a439577
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Media Proxy

Proxy server to transform media files (images and PDFs) present in S3 bucket.

2 changes: 1 addition & 1 deletion internal/mediaprocessor/media_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewMediaProcessor() *MediaProcessor {

func getContentType(imageBytes []byte) string {
contentType := http.DetectContentType(imageBytes)
fmt.Println(contentType)
// fmt.Println(contentType)
if contentType == "text/xml; charset=utf-8" {
contentType = "image/svg+xml"
}
Expand Down
5 changes: 5 additions & 0 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func NewServer(config ServerConfig, mediaProcessor *mediaprocessor.MediaProcesso
mux.Use(s.prometheusMiddleware)
mux.HandleFunc("/{signature}/metadata/*", s.handleMetadataRequest)
mux.HandleFunc("/{signature}/media/*", s.handleTransformRequest)
mux.HandleFunc("/health", s.health)
return s
}

Expand All @@ -118,6 +119,10 @@ func (w *statusWriter) WriteHeader(code int) {
w.ResponseWriter.WriteHeader(code)
}

func (s *server) health(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}

func (s *server) prometheusMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
activeRequests.Inc()
Expand Down

0 comments on commit a439577

Please sign in to comment.