servant-server-0.20.2: A family of combinators for defining webservices APIs and serving them

Safe Haskell | None
Language | Haskell2010

Servant.Server.StaticFiles

Contents

- Deprecated

Description

This module defines server-side handlers that lets you serve static files.

The most common needs for a web application are covered by `serveDirectoryWebApp`, but the other variants allow you to use different `StaticSettings` and `serveDirectoryWith` even allows you to specify arbitrary `StaticSettings` to be used for serving static files.

Synopsis

- serveDirectoryWebApp :: forall (m :: Type -> Type). FilePath -> ServerT Raw m
- serveDirectoryWebAppLookup :: forall (m :: Type -> Type). ETagLookup -> FilePath -> ServerT Raw m
- serveDirectoryFileServer :: forall (m :: Type -> Type). FilePath -> ServerT Raw m
- serveDirectoryEmbedded :: forall (m :: Type -> Type). [(FilePath, ByteString)] -> ServerT Raw m
- serveDirectoryWith :: forall (m :: Type -> Type). StaticSettings -> ServerT Raw m
- serveDirectory :: forall (m :: Type -> Type). FilePath -> ServerT Raw m

# Documentation

serveDirectoryWebApp :: forall (m :: Type -> Type). FilePath -> ServerT Raw m #

Serve anything under the specified directory as a `Raw` endpoint.

    type MyApi = "static" :> Raw

    server :: Server MyApi
    server = serveDirectoryWebApp "/var/www"

would capture any request to `/static/<something>` and look for `<something>` under `/var/www`.

It will do its best to guess the MIME type for that file, based on the extension, and send an appropriate Content-Type header if possible.

If your goal is to serve HTML, CSS and Javascript files that use the rest of the API as a webapp backend, you will most likely not want the static files to be hidden behind a /static/ prefix. In that case, remember to put the `serveDirectoryWebApp` handler in the last position, because servant will try to match the handlers in order.

Corresponds to the `defaultWebAppSettings` `StaticSettings` value.

serveDirectoryWebAppLookup :: forall (m :: Type -> Type). ETagLookup -> FilePath -> ServerT Raw m #

Same as `serveDirectoryWebApp`, but uses `webAppSettingsWithLookup`.

serveDirectoryFileServer :: forall (m :: Type -> Type). FilePath -> ServerT Raw m #

Same as `serveDirectoryWebApp`, but uses `defaultFileServerSettings`.

serveDirectoryEmbedded :: forall (m :: Type -> Type). [(FilePath, ByteString)] -> ServerT Raw m #

Uses `embeddedSettings`.

serveDirectoryWith :: forall (m :: Type -> Type). StaticSettings -> ServerT Raw m #

Alias for `staticApp`. Lets you serve a directory with arbitrary `StaticSettings`. Useful when you want particular settings not covered by the four other variants. This is the most flexible method.

# Deprecated

serveDirectory :: forall (m :: Type -> Type). FilePath -> ServerT Raw m #

Deprecated: Use serveDirectoryFileServer instead

Same as `serveDirectoryFileServer`. It used to be the only file serving function in servant pre-0.10 and will be kept around for a few versions, but is deprecated.