1
0
Эх сурвалжийг харах

add /health endpoint

Returns 200 OK after server starts.

This greatly simplifies container deployment. For example,
Kubernetes can be configured to not route traffic to imgproxy Pods
that did not pass Readiness check against /health.
Mikuláš Dítě 7 жил өмнө
parent
commit
8b7cfa2e25
2 өөрчлөгдсөн 10 нэмэгдсэн , 0 устгасан
  1. 4 0
      README.md
  2. 6 0
      server.go

+ 4 - 0
README.md

@@ -218,6 +218,10 @@ You can find helpful code snippets in the `examples` folder.
 
 
 imgproxy supports only the most popular image formats of the moment: PNG, JPEG, GIF and WebP.
 imgproxy supports only the most popular image formats of the moment: PNG, JPEG, GIF and WebP.
 
 
+## Deployment
+
+There is a special endpoint `/health`, which returns HTTP Status `200 OK` after server successfully starts. This can be used to check container readiness.   
+
 ## Author
 ## Author
 
 
 Sergey "DarthSim" Aleksandrovich
 Sergey "DarthSim" Aleksandrovich

+ 6 - 0
server.go

@@ -175,6 +175,12 @@ func (h *httpHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
 		panic(invalidSecretErr)
 		panic(invalidSecretErr)
 	}
 	}
 
 
+	if r.URL.Path == "/health" {
+		rw.WriteHeader(200);
+		rw.Write([]byte("imgproxy is running"));
+		return
+	}
+
 	imgURL, procOpt, err := parsePath(r)
 	imgURL, procOpt, err := parsePath(r)
 	if err != nil {
 	if err != nil {
 		panic(newError(404, err.Error(), "Invalid image url"))
 		panic(newError(404, err.Error(), "Invalid image url"))