yesod-0.6.7: Creation of type-safe, RESTful web applications.




Serve static files from a Yesod app.

This is most useful for standalone testing. When running on a production server (like Apache), just let the server do the static serving.

In fact, in an ideal setup you'll serve your static files from a separate domain name to save time on transmitting cookies. In that case, you may wish to use urlRenderOverride to redirect requests to this subsite to a separate domain name.



data Static Source

A function for looking up file contents. For serving from the file system, see fileLookupDir.




staticLookup :: FilePath -> IO (Maybe (Either FilePath Content))
staticTypes :: [(String, ContentType)]

Mapping from file extension to content type. See typeByExt.


Lookup files in filesystem

fileLookupDir :: FilePath -> [(String, ContentType)] -> StaticSource

Lookup files in a specific directory.

If you are just using this in combination with the static subsite (you probably are), the handler itself checks that no unsafe paths are being requested. In particular, no path segments may begin with a single period, so hidden files and parent directories are safe.

For the second argument to this function, you can just use typeByExt.

staticFiles :: FilePath -> Q [Dec]Source

This piece of Template Haskell will find all of the files in the given directory and create Haskell identifiers for them. For example, if you have the files "static/style.css" and "static/js/script.js", it will essentailly create:

 style_css = StaticRoute ["style.css"] []
 js_script_js = StaticRoute ["js/script.js"] []

Embed files

mkEmbedFiles :: FilePath -> Q ExpSource

Lookup files in a specific directory, and embed them into the haskell source.

A variation of fileLookupDir which allows subsites distributed via cabal to include static content. You can still use staticFiles to generate route identifiers. See getStaticHandler for dispatching static content for a subsite.

getStaticHandler :: Static -> (StaticRoute -> Route sub) -> [String] -> GHandler sub y ChooseRepSource

Dispatch static route for a subsite

Subsites with static routes can't (yet) define Static routes the same way master sites can. Instead of a subsite route: /static StaticR Static getStatic Use a normal route: /static end CPP comment


base64md5 :: ByteString -> StringSource

md5-hashes the given lazy bytestring and returns the hash as base64url-encoded string.

This function returns the first 8 characters of the hash.