-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
baac32d
commit 94fe8e7
Showing
4 changed files
with
30 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Proxy.Run (run) where | ||
|
||
import Imports hiding (head) | ||
import Control.Monad.Catch | ||
import Control.Lens hiding ((.=)) | ||
import Data.Metrics.Middleware hiding (path) | ||
import Data.Metrics.Middleware.Prometheus (waiPrometheusMiddleware) | ||
import Data.Metrics.WaiRoute (treeToPaths) | ||
import Network.Wai.Utilities.Server hiding (serverPort) | ||
import Network.Wai.Handler.Warp (runSettings) | ||
import Proxy.Env | ||
import Proxy.Proxy | ||
import Proxy.Options | ||
import Proxy.API (sitemap) | ||
|
||
run :: Opts -> IO () | ||
run o = do | ||
m <- metrics | ||
e <- createEnv m o | ||
s <- newSettings $ defaultServer (o^.host) (o^.port) (e^.applog) m | ||
let rtree = compile (sitemap e) | ||
let measured = measureRequests m (treeToPaths rtree) | ||
let app r k = runProxy e r (route rtree r k) | ||
let middleware = waiPrometheusMiddleware (sitemap e) | ||
. measured | ||
. catchErrors (e^.applog) m | ||
runSettings s (middleware app) `finally` destroyEnv e |