datarekisteri/frontend/src/Datarekisteri/Frontend.hs

47 lines
1.6 KiB
Haskell
Raw Normal View History

2023-01-20 09:20:06 +02:00
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE NoImplicitPrelude #-}
import Relude hiding (get)
import Yesod
import Yesod.Auth
import Datarekisteri.Frontend.Types
import Datarekisteri.Frontend.Handlers
import Datarekisteri.Frontend.Auth ()
2023-01-20 09:20:06 +02:00
import Yesod.Static (static, Static)
2023-09-15 18:05:58 +03:00
import Options.Applicative
2023-01-20 09:20:06 +02:00
import System.Directory (createDirectoryIfMissing)
mkYesodDispatch "DataIdClient" resourcesDataIdClient
main :: IO ()
2023-09-15 18:05:58 +03:00
main = do
2023-09-21 07:37:07 +03:00
config <- readConfig
2023-09-15 18:05:58 +03:00
static <- getStaticDir "/tmp/data-id"
2023-09-21 07:37:07 +03:00
warp (configPort config) $ DataIdClient static config
2023-09-15 18:05:58 +03:00
2023-09-21 07:37:07 +03:00
readConfig :: IO Config
2023-09-15 18:05:58 +03:00
readConfig = execParser $ info (configOpts' <**> helper)
2023-09-21 07:37:07 +03:00
(fullDesc <> progDesc "Serve datarekisteri HTTP client"
<> header "Client HTTP server for datarekisteri")
configOpts' :: Parser Config
configOpts' = Config
<$> option auto (long "port" <> short 'p' <> metavar "PORT" <> value 3000 <> help "Port to listen on")
<*> strOption (long "approot" <> short 'r' <> metavar "URL" <> value "http://localhost:3000" <> help "External URL of the server path /")
<*> strOption (long "server-url" <> short 's' <> metavar "URL" <> value "http://localhost:3100" <> help "Internal URL of the API server")
2023-09-15 18:05:58 +03:00
-- TODO make port depend on the --port flag
2023-01-20 09:20:06 +02:00
getStaticDir :: FilePath -> IO Static
getStaticDir dir = createDirectoryIfMissing True dir >> static dir