Merge pull request #267 from fpco/healthz-as-middleware

healthz is a middleware
This commit is contained in:
Deni Bertovic 2019-06-20 14:08:34 +02:00 committed by GitHub
commit f909a18e83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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