Define settings for a Yesod applications. All methods have intelligent defaults, and therefore no implementation is required.
Methods
approot :: Approot siteAn absolute URL to the root of the application. Do not include trailing slash.
Default value: guessApproot. If you know your application root statically, it will be more efficient and more reliable to instead use ApprootStatic or ApprootMaster. If you do not need full absolute URLs, you can use ApprootRelative instead.
Note: Prior to yesod-core 1.5, the default value was ApprootRelative.
catchHandlerExceptions :: MonadUnliftIO m => site -> m a -> (SomeException -> m a) -> m aallows the user to specify how exceptions are cought. by default all async exceptions are thrown and synchronous exceptions render a 500 page. To catch all exceptions (even async) to render a 500 page, set this to catchSyncOrAsync. Beware this may have negative effects with functions like
timeout.errorHandler :: ErrorResponse -> HandlerFor site TypedContentOutput error response pages.
Default value: defaultErrorHandler.
defaultLayout :: WidgetFor site () -> HandlerFor site HtmlApplies some form of layout to the contents of a page.
urlParamRenderOverride :: site -> Route site -> [(Text, Text)] -> Maybe BuilderOverride the rendering function for a particular URL and query string parameters. One use case for this is to offload static hosting to a different domain name to avoid sending cookies.
For backward compatibility default implementation is in terms of
urlRenderOverride, probably ineffectiveSince 1.4.23
isAuthorized :: Route site -> Bool -> HandlerFor site AuthResultDetermine if a request is authorized or not.
Return Authorized if the request is authorized, Unauthorized a message if unauthorized. If authentication is required, return AuthenticationRequired.
isWriteRequest :: Route site -> HandlerFor site BoolDetermines whether the current request is a write request. By default, this assumes you are following RESTful principles, and determines this from request method. In particular, all except the following request methods are considered write: GET HEAD OPTIONS TRACE.
This function is used to determine if a request is authorized; see isAuthorized.
authRoute :: site -> Maybe (Route site)The default route for authentication.
Used in particular by isAuthorized, but library users can do whatever they want with it.
cleanPath :: site -> [Text] -> Either [Text] [Text]A function used to clean up path segments. It returns Right with a clean path or Left with a new set of pieces the user should be redirected to. The default implementation enforces:
No double slashes
There is no trailing slash.
Note that versions of Yesod prior to 0.7 used a different set of rules involing trailing slashes.
joinPath :: site -> Text -> [Text] -> [(Text, Text)] -> BuilderBuilds an absolute URL by concatenating the application root with the pieces of a path and a query string, if any. Note that the pieces of the path have been previously cleaned up by cleanPath.
addStaticContent :: Text -> Text -> ByteString -> HandlerFor site (Maybe (Either Text (Route site, [(Text, Text)])))This function is used to store some static content to be served as an external file. The most common case of this is stashing CSS and JavaScript content in an external file; the
Yesod.Widgetmodule uses this feature.The return value is Nothing if no storing was performed; this is the default implementation. A Just Left gives the absolute URL of the file, whereas a Just Right gives the type-safe URL. The former is necessary when you are serving the content outside the context of a Yesod application, such as via memcached.
maximumContentLength :: site -> Maybe (Route site) -> Maybe Word64Maximum allowed length of the request body, in bytes. This method may be ignored if maximumContentLengthIO is overridden.
If
Nothing, no maximum is applied.Default: 2 megabytes.
maximumContentLengthIO :: site -> Maybe (Route site) -> IO (Maybe Word64)Maximum allowed length of the request body, in bytes. This is similar to maximumContentLength, but the result lives in
IO. This allows you to dynamically change the maximum file size based on some external source like a database or anIORef.The default implementation uses maximumContentLength. Future version of yesod will remove maximumContentLength and use this method exclusively.
makeLogger :: site -> IO LoggerCreates a
Loggerto use for log messages.Note that a common technique (endorsed by the scaffolding) is to create a
Loggervalue and place it in your foundation datatype, and have this method return that already created value. That way, you can use that sameLoggerfor printing messages during app initialization.Default: the defaultMakeLogger function.
messageLoggerSource :: site -> Logger -> Loc -> LogSource -> LogLevel -> LogStr -> IO ()Send a message to the
Loggerprovided bygetLogger.Default: the defaultMessageLoggerSource function, using shouldLogIO to check whether we should log.
jsLoader :: site -> ScriptLoadPosition siteWhere to Load sripts from. We recommend the default value, BottomOfBody.
jsAttributes :: site -> [(Text, Text)]Default attributes to put on the JavaScript script tag generated for julius files
jsAttributesHandler :: HandlerFor site [(Text, Text)]Same as
jsAttributesbut allows you to run arbitrary Handler codeThis is useful if you need to add a randomised nonce value to the script tag generated by
widgetFile. If this function is overridden thenjsAttributesis ignored.makeSessionBackend :: site -> IO (Maybe SessionBackend)Create a session backend. Returning Nothing disables sessions. If you'd like to change the way that the session cookies are created, take a look at customizeSessionCookies.
Default: Uses clientsession with a 2 hour timeout.
fileUpload :: site -> RequestBodyLength -> FileUploadHow to store uploaded files.
Default: When the request body is greater than 50kb, store in a temp file. For chunked request bodies, store in a temp file. Otherwise, store in memory.
shouldLogIO :: site -> LogSource -> LogLevel -> IO BoolShould we log the given log source/level combination.
Default: the defaultShouldLogIO function.
Since 1.2.4
yesodMiddleware :: ToTypedContent res => HandlerFor site res -> HandlerFor site resA Yesod middleware, which will wrap every handler function. This allows you to run code before and after a normal handler.
Default: the defaultYesodMiddleware function.
Since: 1.1.6
yesodWithInternalState :: site -> Maybe (Route site) -> (InternalState -> IO a) -> IO aHow to allocate an
InternalStatefor each request.The default implementation is almost always what you want. However, if you know that you are never taking advantage of the
MonadResourceinstance in your handler functions, setting this to a dummy implementation can provide a small optimization. Only do this if you really know what you're doing, otherwise you can turn safe code into a runtime error!Since 1.4.2
defaultMessageWidget :: Html -> HtmlUrl (Route site) -> WidgetFor site ()Convert a title and HTML snippet into a
Widget. Used primarily for wrapping up error messages for better display.