Skip to content

Commit

Permalink
Default to guessApproot #114
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Dec 4, 2015
1 parent 5880221 commit ab5ad2e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
5 changes: 4 additions & 1 deletion Foundation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion PROJECTNAME.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions Settings.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
5 changes: 4 additions & 1 deletion config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down

0 comments on commit ab5ad2e

Please sign in to comment.