(optionally) read config path from cmdline arguments
This commit is contained in:
parent
56b0689b04
commit
f29cdcb3c2
@ -29,10 +29,13 @@ createEmptyIfMissing file = do
|
||||
when (not exists) (writeFile file "")
|
||||
|
||||
|
||||
settings :: IO AppSettings
|
||||
settings = do
|
||||
urlsPath <- getUserDataFile "breve" ""
|
||||
configPath <- getUserConfigFile "breve" ""
|
||||
settings :: Maybe FilePath -> IO AppSettings
|
||||
settings path = do
|
||||
configPath <- case path of
|
||||
Just path -> return path
|
||||
Nothing -> getUserConfigFile "breve" ""
|
||||
|
||||
urlsPath <- getUserDataFile "breve" ""
|
||||
|
||||
config <- load [Required configPath]
|
||||
host <- lookupDefault "localhost" config "hostname"
|
||||
|
@ -5,8 +5,10 @@ import Breve.Settings
|
||||
import Breve.UrlTable
|
||||
|
||||
import Data.Text (Text, unpack)
|
||||
import Data.Maybe (listToMaybe)
|
||||
import Control.Concurrent (forkIO)
|
||||
import Control.Monad
|
||||
import System.Environment (getArgs)
|
||||
|
||||
import Web.Spock.Core
|
||||
import Network.Wai.Handler.WarpTLS (runTLS, TLSSettings)
|
||||
@ -28,7 +30,8 @@ forkIO' = fmap (const ()) . forkIO
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
AppSettings {..} <- settings
|
||||
configPath <- fmap listToMaybe getArgs
|
||||
AppSettings {..} <- settings configPath
|
||||
table <- load urlTable
|
||||
|
||||
when (bindPort == 443) (forkIO' $ runTLSRedirect bindHost)
|
||||
|
Loading…
Reference in New Issue
Block a user