35 lines
798 B
Haskell
35 lines
798 B
Haskell
|
{-# LANGUAGE DataKinds #-}
|
||
|
{-# LANGUAGE TemplateHaskell #-}
|
||
|
{-# LANGUAGE TypeOperators #-}
|
||
|
module Lib
|
||
|
( startApp
|
||
|
, app
|
||
|
) where
|
||
|
|
||
|
import Data.Bytestring
|
||
|
import Data.Maybe
|
||
|
import Network.Wai
|
||
|
import Network.Wai.Handler.Warp
|
||
|
import Servant
|
||
|
|
||
|
import Routes
|
||
|
|
||
|
startApp :: IO ()
|
||
|
startApp = do
|
||
|
dbURL <- getEnv "DATABASE_URL"
|
||
|
let ci = fromJust $ parseDatabaseURL dbURL
|
||
|
let cs = postgreSQLConnectionString ci
|
||
|
let dbConnectionString = unpack cs
|
||
|
pool <- createPostgresqlPool dbConnectionString 5
|
||
|
|
||
|
runDbConn $ do
|
||
|
runMigration defaultMigrationLogger $ do
|
||
|
migrate (undefined :: Models.App)
|
||
|
migrate (undefined :: Models.Endpoint)
|
||
|
migrate (undefined :: Models.Event)
|
||
|
|
||
|
run 8080 $ app pool
|
||
|
|
||
|
app :: Pool Postgresql -> Application
|
||
|
app pool = serve api $ server pool
|