Safe Haskell | Safe-Infered |
---|
Serve static files, subject to a policy that can filter or modify incoming URIs. The flow is:
incoming request URI ==> policies ==> exists? ==> respond
If any of the polices fail (return Nothing), or the file doesn't exist, then the middleware gives up and calls the inner application. If the file is found, the middleware chooses a content type based on the file extension and returns the file contents as the response.
Middlewares
Serve static files out of the application root (current directory). If file is found, it is streamed to the client and no further middleware is run.
staticPolicy :: Policy -> MiddlewareSource
Serve static files subject to a Policy
Policies
type Policy = String -> Maybe StringSource
Take an incoming URI and optionally modify or filter it. The result will be treated as a filepath.
addBase :: String -> PolicySource
Add a base path to the URI
staticPolicy (addBase "/home/user/files")
GET "foo/bar" looks for "/home/user/files/foo/bar"
Add an initial slash to to the URI, if not already present.
staticPolicy addSlash
GET "foo/bar" looks for "/foo/bar"