healthz is a middleware

This commit is contained in:
Michael Snoyman 2019-06-19 12:07:08 +03:00
parent 98d0d61958
commit 0eea4ca99a
No known key found for this signature in database
GPG Key ID: A048E8C057E86876
2 changed files with 10 additions and 2 deletions

View File

@ -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 ->

View File

@ -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