From cddd15133a0e4a8c1ba978f1b845de8b7a726944 Mon Sep 17 00:00:00 2001 From: arnonsang Date: Sun, 7 Jul 2024 22:27:36 +0700 Subject: [PATCH] Feat(health): head support --- docker-compose.yml | 10 +--------- presentation/server.go | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 1352b29..44a2b34 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,3 @@ -version: '3' services: app: build: @@ -12,11 +11,4 @@ services: - ./assets:/app/assets environment: - ENV_VAR=value - restart: unless-stopped - healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:8089/healthz"] - interval: 15m - timeout: 10s - retries: 5 - start_period: 30s - \ No newline at end of file + restart: unless-stopped \ No newline at end of file diff --git a/presentation/server.go b/presentation/server.go index 3e34fb0..2debb30 100644 --- a/presentation/server.go +++ b/presentation/server.go @@ -36,21 +36,24 @@ func (s *Server) Start(address string) error { func (s *Server) setupMiddleware() { s.e.Use(middleware.Logger()) s.e.Use(middleware.Recover()) - s.e.Use(middleware.CORS()) - s.e.Use(middleware.Secure()) - s.e.Use(middleware.RequestID()) - s.e.Use(middleware.CSRF()) - s.e.Use(middleware.Gzip()) - s.e.Use(middleware.Decompress()) + s.e.Use(middleware.CORSWithConfig(middleware.CORSConfig{ + AllowOrigins: []string{"*"}, + AllowMethods: []string{http.MethodGet, http.MethodPost}, + })) + // s.e.Use(middleware.Secure()) + // s.e.Use(middleware.RequestID()) + // s.e.Use(middleware.CSRF()) + // s.e.Use(middleware.Gzip()) + // s.e.Use(middleware.Decompress()) s.e.Use(middleware.BodyLimit("2M")) s.e.Use(middleware.RateLimiter(middleware.NewRateLimiterMemoryStore(20))) s.e.Use(middleware.TimeoutWithConfig(middleware.TimeoutConfig{ Skipper: middleware.DefaultSkipper, - ErrorMessage: "Request timeout after 30 seconds, please try again later", + ErrorMessage: "Request timeout after 60 seconds, please try again later", OnTimeoutRouteErrorHandler: func(err error, c echo.Context) { log.Println(c.Path()) }, - Timeout: 30 * time.Second, + Timeout: 60 * time.Second, })) } @@ -67,6 +70,9 @@ func (s *Server) setupRoutes() { res := map[string]string{"status": "ok"} return c.JSON(http.StatusOK, res) }) + s.e.HEAD("/healthz", func(c echo.Context) error { + return c.NoContent(http.StatusOK) + }) } func (s *Server) getWord(c echo.Context) error {