Restore the staticRoot option from older versions of Yesod's scaffolding, so I can host static files on a subdomain easily

This commit is contained in:
Danielle McLean 2017-10-02 20:31:49 +11:00
parent a981947374
commit 1794e63bb0
Signed by: 00dani
GPG key ID: 3844A6973C6058F1
3 changed files with 18 additions and 3 deletions

View file

@ -6,9 +6,8 @@ host: "_env:HOST:127.0.0.1"
port: "_env:PORT:3000" # NB: The port `yesod devel` uses is distinct from this value. Set the `yesod devel` port from the command line.
ip-from-header: "_env:IP_FROM_HEADER:true"
# Default behavior: determine the application root from the request headers.
# Uncomment to set an explicit approot
#approot: "_env:APPROOT:http://localhost:3000"
approot: "_env:APPROOT:https://00dani.dev"
static-root: "_env:STATIC_ROOT:https://static.00dani.dev"
# Optional values with the following production defaults.
# In development, they default to the inverse.

View file

@ -77,6 +77,16 @@ instance Yesod App where
120 -- timeout in minutes
"config/client_session_key.aes"
-- Redirect static requests to a subdomain - this is recommended for best
-- performance, since serving static files does not need your session
-- cookies and they can be served from the frontend HTTP server without
-- hitting the app server at all.
-- https://github.com/yesodweb/yesod-cookbook/blob/master/cookbook/Serve-static-files-from-a-separate-domain.md
urlParamRenderOverride app (StaticR s) _ = do
staticRoot <- appStaticRoot . appSettings $ app
return . uncurry (joinPath app staticRoot) . renderRoute $ s
urlParamRenderOverride _ _ _ = Nothing
-- Yesod Middleware allows you to run code before and after each handler function.
-- The defaultYesodMiddleware adds the response header "Vary: Accept, Accept-Language" and performs authorization checks.
-- Some users may also want to add the defaultCsrfMiddleware, which:

View file

@ -43,6 +43,10 @@ data AppSettings = AppSettings
-- ^ Get the IP address from the header when logging. Useful when sitting
-- behind a reverse proxy.
, appStaticRoot :: Maybe Text
-- ^ Base for static generated URLs. Useful for serving static assets from
-- a separate domain. If @Nothing@, use @appRoot@ and @appStaticDir@ instead.
, appDetailedRequestLogging :: Bool
-- ^ Use detailed request logging system
, appShouldLogAll :: Bool
@ -79,6 +83,8 @@ instance FromJSON AppSettings where
appPort <- o .: "port"
appIpFromHeader <- o .: "ip-from-header"
appStaticRoot <- o .:? "static-root"
appDetailedRequestLogging <- o .:? "detailed-logging" .!= defaultDev
appShouldLogAll <- o .:? "should-log-all" .!= defaultDev
appReloadTemplates <- o .:? "reload-templates" .!= defaultDev