diff --git a/Foundation.hs b/Foundation.hs index aba8b34..106d55b 100644 --- a/Foundation.hs +++ b/Foundation.hs @@ -46,7 +46,10 @@ type Form x = Html -> MForm (HandlerT App IO) (FormResult x, Widget) instance Yesod App where -- Controls the base of generated URLs. For more information on modifying, -- see: https://github.com/yesodweb/yesod/wiki/Overriding-approot - approot = ApprootMaster $ appRoot . appSettings + approot = ApprootRequest $ \app req -> + case appRoot $ appSettings app of + Nothing -> getApprootText guessApproot app req + Just root -> root -- Store session data on the client in encrypted cookies, -- default session idle timeout is 120 minutes diff --git a/PROJECTNAME.cabal b/PROJECTNAME.cabal index 087b0c3..278b74d 100644 --- a/PROJECTNAME.cabal +++ b/PROJECTNAME.cabal @@ -49,7 +49,7 @@ library build-depends: base >= 4 && < 5 , yesod >= 1.4.1 && < 1.5 - , yesod-core >= 1.4.14 && < 1.5 + , yesod-core >= 1.4.17 && < 1.5 , yesod-auth >= 1.4.0 && < 1.5 , yesod-static >= 1.4.0.3 && < 1.6 , yesod-form >= 1.4.0 && < 1.5 diff --git a/Settings.hs b/Settings.hs index f6c652b..01b6117 100644 --- a/Settings.hs +++ b/Settings.hs @@ -27,8 +27,9 @@ data AppSettings = AppSettings -- ^ Directory from which to serve static files. , appDatabaseConf :: PostgresConf -- ^ Configuration settings for accessing the database. - , appRoot :: Text - -- ^ Base for all generated URLs. + , appRoot :: Maybe Text + -- ^ Base for all generated URLs. If @Nothing@, determined + -- from the request headers. , appHost :: HostPreference -- ^ Host/interface the server should bind to. , appPort :: Int @@ -65,7 +66,7 @@ instance FromJSON AppSettings where #endif appStaticDir <- o .: "static-dir" appDatabaseConf <- o .: "database" - appRoot <- o .: "approot" + appRoot <- o .:? "approot" appHost <- fromString <$> o .: "host" appPort <- o .: "port" appIpFromHeader <- o .: "ip-from-header" diff --git a/config/settings.yml b/config/settings.yml index 4994b28..0b44dec 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -4,9 +4,12 @@ static-dir: "_env:STATIC_DIR:static" host: "_env:HOST:*4" # any IPv4 host port: "_env:PORT:3000" # NB: The port `yesod devel` uses is distinct from this value. Set the `yesod devel` port from the command line. -approot: "_env:APPROOT:http://localhost:3000" ip-from-header: "_env:IP_FROM_HEADER:false" +# Default behavior: determine the application root from the request headers. +# Uncomment to set an explicit approot +#approot: "_env:APPROOT:http://localhost:3000" + # Optional values with the following production defaults. # In development, they default to the inverse. #