diff --git a/src/Application.hs b/src/Application.hs index 144c9dd..ab35795 100644 --- a/src/Application.hs +++ b/src/Application.hs @@ -29,7 +29,7 @@ import Data.WebsiteContent import Database.Persist.Postgresql (PostgresConf(..)) import Import hiding (catch) import Language.Haskell.TH.Syntax (qLocation) -import Network.Wai (Middleware, rawPathInfo) +import Network.Wai (Middleware, rawPathInfo, pathInfo, responseBuilder) import Network.Wai.Handler.Warp (Settings, defaultSettings, defaultShouldDisplayException, getPort, runSettings, setHost, setOnException, setPort) @@ -91,6 +91,7 @@ makeApplication foundation = do appPlain <- toWaiAppPlain foundation let middleware = id -- prometheus def + . healthz #if !DEVELOPMENT . forceSSL' (appSettings foundation) #endif @@ -101,6 +102,13 @@ makeApplication foundation = do return (middleware appPlain) +-- | Bypass any overhead from Yesod +healthz :: Middleware +healthz app req send = + case pathInfo req of + ["healthz"] -> send $ responseBuilder status200 [("content-type", "text/plain; charset=utf-8")] "OK" + _ -> app req send + forceSSL' :: AppSettings -> Middleware forceSSL' settings app | appForceSsl settings = \req send -> diff --git a/src/Handler/Home.hs b/src/Handler/Home.hs index a4aa4ca..a02bb75 100644 --- a/src/Handler/Home.hs +++ b/src/Handler/Home.hs @@ -17,7 +17,7 @@ import Stackage.Database import Yesod.GitRepo (grContent) getHealthzR :: Handler String -getHealthzR = return "OK" +getHealthzR = return "This should never be used, we should use the middleware instead" -- This is a handler function for the G request method on the HomeR -- resource pattern. All of your resource patterns are defined in