(optionally) read config path from cmdline arguments

master
rnhmjoj 2017-02-21 17:00:30 +01:00
parent 56b0689b04
commit f29cdcb3c2
No known key found for this signature in database
GPG Key ID: 362BB82B7E496B7C
2 changed files with 11 additions and 5 deletions

View File

@ -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"

View File

@ -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)