mirror of
https://github.com/commercialhaskell/stackage-server.git
synced 2026-01-30 12:50:24 +01:00
Merge pull request #267 from fpco/healthz-as-middleware
healthz is a middleware
This commit is contained in:
commit
f909a18e83
@ -29,7 +29,7 @@ import Data.WebsiteContent
|
|||||||
import Database.Persist.Postgresql (PostgresConf(..))
|
import Database.Persist.Postgresql (PostgresConf(..))
|
||||||
import Import hiding (catch)
|
import Import hiding (catch)
|
||||||
import Language.Haskell.TH.Syntax (qLocation)
|
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,
|
import Network.Wai.Handler.Warp (Settings, defaultSettings,
|
||||||
defaultShouldDisplayException, getPort,
|
defaultShouldDisplayException, getPort,
|
||||||
runSettings, setHost, setOnException, setPort)
|
runSettings, setHost, setOnException, setPort)
|
||||||
@ -91,6 +91,7 @@ makeApplication foundation = do
|
|||||||
appPlain <- toWaiAppPlain foundation
|
appPlain <- toWaiAppPlain foundation
|
||||||
|
|
||||||
let middleware = id -- prometheus def
|
let middleware = id -- prometheus def
|
||||||
|
. healthz
|
||||||
#if !DEVELOPMENT
|
#if !DEVELOPMENT
|
||||||
. forceSSL' (appSettings foundation)
|
. forceSSL' (appSettings foundation)
|
||||||
#endif
|
#endif
|
||||||
@ -101,6 +102,13 @@ makeApplication foundation = do
|
|||||||
|
|
||||||
return (middleware appPlain)
|
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' :: AppSettings -> Middleware
|
||||||
forceSSL' settings app
|
forceSSL' settings app
|
||||||
| appForceSsl settings = \req send ->
|
| appForceSsl settings = \req send ->
|
||||||
|
|||||||
@ -17,7 +17,7 @@ import Stackage.Database
|
|||||||
import Yesod.GitRepo (grContent)
|
import Yesod.GitRepo (grContent)
|
||||||
|
|
||||||
getHealthzR :: Handler String
|
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
|
-- This is a handler function for the G request method on the HomeR
|
||||||
-- resource pattern. All of your resource patterns are defined in
|
-- resource pattern. All of your resource patterns are defined in
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user