1-- | This module defines a sever-side handler that lets you serve static files.
3-- - 'serveDirectory' lets you serve anything that lives under a particular
4-- directory on your filesystem.
5module Servant.Utils.StaticFiles (
9import Filesystem.Path.CurrentOS (decodeString)
10import Network.Wai.Application.Static (staticApp, defaultFileServerSettings)
11import Servant.API.Raw (Raw)
12import Servant.Server (Server)
14-- | Serve anything under the specified directory as a 'Raw' endpoint.
17-- type MyApi = "static" :> Raw
19-- server :: Server MyApi
20-- server = serveDirectory "\/var\/www"
23-- would capture any request to @\/static\/\<something>@ and look for
24-- @\<something>@ under @\/var\/www@.
26-- It will do its best to guess the MIME type for that file, based on the extension,
27-- and send an appropriate /Content-Type/ header if possible.
29-- If your goal is to serve HTML, CSS and Javascript files that use the rest of the API
30-- as a webapp backend, you will most likely not want the static files to be hidden
31-- behind a /\/static\// prefix. In that case, remember to put the 'serveDirectory'
32-- handler in the last position, because /servant/ will try to match the handlers
34serveDirectory :: FilePath -> Server Raw
35serveDirectory documentRoot =
36 staticApp (defaultFileServerSettings (decodeString (documentRoot ++ "/")))
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list