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