tiny: don't port to appRoot if 80

This commit is contained in:
Greg Weber 2011-09-01 05:40:36 -07:00
parent 0c242baded
commit 55c86c546b
2 changed files with 13 additions and 9 deletions

View File

@ -85,19 +85,19 @@ loadConfig :: AppEnvironment -> IO AppConfig
loadConfig env = do loadConfig env = do
allSettings <- (join $ YAML.decodeFile ("config/settings.yml" :: String)) >>= fromMapping allSettings <- (join $ YAML.decodeFile ("config/settings.yml" :: String)) >>= fromMapping
settings <- lookupMapping (show env) allSettings settings <- lookupMapping (show env) allSettings
portS <- lookupScalar "port" settings
hostS <- lookupScalar "host" settings hostS <- lookupScalar "host" settings
port <- fmap read $ lookupScalar "port" settings
connectionPoolSizeS <- lookupScalar "connectionPoolSize" settings connectionPoolSizeS <- lookupScalar "connectionPoolSize" settings
return $ AppConfig { return $ AppConfig {
appEnv = env appEnv = env
, appPort = read portS , appPort = port
, appRoot = maybeAddPort hostS portS , appRoot = pack $ hostS ++ maybeAddPort port
, connectionPoolSize = read connectionPoolSizeS , connectionPoolSize = read connectionPoolSizeS
} }
where where
maybeAddPort :: String -> String -> Text maybeAddPort :: Int -> String
maybeAddPort h p = pack $ if p == "80" then h else h ++ ":" ++ p maybeAddPort 80 = ""
maybeAddPort p = ":" ++ (show p)
-- Static setting below. Changing these requires a recompile -- Static setting below. Changing these requires a recompile

View File

@ -67,13 +67,17 @@ loadConfig :: AppEnvironment -> IO AppConfig
loadConfig env = do loadConfig env = do
allSettings <- (join $ YAML.decodeFile ("config/settings.yml" :: String)) >>= fromMapping allSettings <- (join $ YAML.decodeFile ("config/settings.yml" :: String)) >>= fromMapping
settings <- lookupMapping (show env) allSettings settings <- lookupMapping (show env) allSettings
portS <- lookupScalar "port" settings
hostS <- lookupScalar "host" settings hostS <- lookupScalar "host" settings
port <- fmap read $ lookupScalar "port" settings
return $ AppConfig { return $ AppConfig {
appEnv = env appEnv = env
, appPort = read portS , appPort = port
, appRoot = pack (hostS ++ ":" ++ portS) , appRoot = pack $ hostS ++ maybeAddPort port
} }
where
maybeAddPort :: Int -> String
maybeAddPort 80 = ""
maybeAddPort p = ":" ++ (show p)
-- | The location of static files on your system. This is a file system -- | The location of static files on your system. This is a file system
-- path. The default value works properly with your scaffolded site. -- path. The default value works properly with your scaffolded site.