From b6e8389edd486d407025383825a1beaf6b7f63b7 Mon Sep 17 00:00:00 2001 From: William Carroll Date: Thu, 30 Jul 2020 13:58:50 +0100 Subject: Read env variables using envy library Using my dear friend's, dmjio's, excellent library, envy -- to read and parse variables from the system environment. I added and git-ignored the .envrc file that contains API secrets. I'm using Envy to read these values, so that I don't hard-code these values into the source code. --- src/App.hs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/App.hs') diff --git a/src/App.hs b/src/App.hs index 708dd896fab2..7536e3c771e1 100644 --- a/src/App.hs +++ b/src/App.hs @@ -37,15 +37,15 @@ err429 = ServerError , errHeaders = [] } -server :: FilePath -> Server API -server dbFile = createAccount - :<|> deleteAccount - :<|> listAccounts - :<|> createTrip - :<|> deleteTrip - :<|> listTrips - :<|> login - :<|> logout +server :: T.Config -> Server API +server T.Config{..} = createAccount + :<|> deleteAccount + :<|> listAccounts + :<|> createTrip + :<|> deleteTrip + :<|> listTrips + :<|> login + :<|> logout where -- Admit Admins + whatever the predicate `p` passes. adminsAnd cookie p = Auth.assert dbFile cookie (\acct@T.Account{..} -> accountRole == T.Admin || p acct) @@ -124,6 +124,6 @@ server dbFile = createAccount liftIO $ Sessions.delete dbFile uuid pure $ addHeader Auth.emptyCookie NoContent -run :: FilePath -> IO () -run dbFile = - Warp.run 3000 (serve (Proxy @ API) $ server dbFile) +run :: T.Config -> IO () +run config = + Warp.run 3000 (serve (Proxy @ API) $ server config) -- cgit 1.4.1