aboutsummaryrefslogtreecommitdiff
path: root/app/Main.hs
blob: ec4b5e77502dc0c15478120a2f24fe525cc88c3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{-# LANGUAGE LambdaCase #-}

-- | The main module. Does little more than handle some basic ocnfic, then
-- call the server
module Main where


import           Control.Monad.IO.Class               (MonadIO (liftIO))
import           Control.Monad.Logger                 (runStderrLoggingT)
import           Data.Default.Class                   (def)
import           Database.Persist.Postgresql
import           Network.Wai.Handler.Warp             (run)
import           Network.Wai.Middleware.RequestLogger (OutputFormat (..),
                                                       RequestLoggerSettings (..),
                                                       mkRequestLogger)
import System.Environment (getArgs)
import Data.Functor ((<&>))
import Data.ByteString.Internal (packChars)

import           GTFS
import           Server


main :: IO ()
main = do
  connStr <- getArgs <&> \case {[str] -> packChars str; _ -> ""}

  gtfs <- loadGtfs "./gtfs.zip"
  loggerMiddleware <- mkRequestLogger
    $ def { outputFormat = Detailed True }
  runStderrLoggingT $ withPostgresqlPool connStr 10 $ \pool -> liftIO $ do
    app <- application gtfs pool
    putStrLn "starting server …"
    run 4000 (loggerMiddleware app)