specify port via command line args
This commit is contained in:
parent
751f3a463a
commit
58423c6466
26
app/Main.hs
26
app/Main.hs
@ -2,5 +2,29 @@ module Main (main) where
|
||||
|
||||
import Server
|
||||
|
||||
import Control.Applicative ((<|>))
|
||||
|
||||
import qualified Data.Map as M
|
||||
|
||||
import System.Environment (getArgs)
|
||||
|
||||
main :: IO ()
|
||||
main = putStrLn "Try: http://localhost:8080/auth?scope=ID%20Profile&client_id=42&response_type=code&redirect_uri=localhost" >> runMockServer 8080
|
||||
main = do
|
||||
args <- getArgs >>= flip buildArgs M.empty
|
||||
port <- determinePort args
|
||||
putStrLn $ "Try: http://localhost:" ++ show port ++ "/auth?scope=ID%20Profile&client_id=42&response_type=code&redirect_uri=localhost"
|
||||
runMockServer port
|
||||
where
|
||||
buildArgs :: [String] -> M.Map String String -> IO (M.Map String String)
|
||||
buildArgs [] m = return m
|
||||
buildArgs (k:v:xs) m = return (M.insert k v m) >>= buildArgs xs
|
||||
buildArgs _ _ = error "invalid command line args"
|
||||
|
||||
determinePort :: M.Map String String -> IO Int
|
||||
determinePort args = do
|
||||
case M.lookup "-p" args <|> M.lookup "--port" args of
|
||||
Just port -> return $ read port
|
||||
Nothing -> return 9443
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user