From 621a91776a6512fc23664e8b2e7ab796ed9ffcd5 Mon Sep 17 00:00:00 2001 From: Lia Lenckowski Date: Sun, 20 Aug 2023 20:00:16 +0200 Subject: better config system --- src/Main.hs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/Main.hs') diff --git a/src/Main.hs b/src/Main.hs index b5b35a1..3474040 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -54,7 +54,8 @@ instance FromJSON PendingBang where data Search = Search { bangState :: BangState, - sqlPool :: ConnectionPool + sqlPool :: ConnectionPool, + config :: Config } mkYesod "Search" [parseRoutes| @@ -123,7 +124,8 @@ getOpenSearchR :: Handler TypedContent getOpenSearchR = do neverExpires - resXml <- liftIO . makeOpenSearch =<< lookupGetParam "default" + cfg <- config <$> getYesod + resXml <- makeOpenSearch cfg <$> lookupGetParam "default" return $ TypedContent "application/opensearchdescription+xml" $ toContent resXml postVerdictR :: Bool -> Handler () @@ -155,15 +157,13 @@ main :: IO () main = runStdoutLoggingT $ withSqlitePool "banger.db" 2 $ \pool -> do runResourceT $ flip runSqlPool pool $ runMigration migrateAll - s <- Search - <$> liftIO initBangState - <*> pure pool - sApp <- liftIO $ toWaiApp s -- includes middlewares + bs <- liftIO initBangState + cfg <- liftIO getConfig + + sApp <- liftIO $ toWaiApp $ Search bs pool cfg -- includes middlewares - host <- liftIO getHost - port <- liftIO getPort let settings = defaultSettings - & setHost host - & setPort port + & setHost (confHost cfg) + & setPort (confPort cfg) liftIO $ runSettings settings sApp -- cgit v1.2.3-70-g09d2