Options

public struct Options

Configuration options for StaticFileServer.

  • Initialize an Options instance.

    Declaration

    Swift

    public init(possibleExtensions: [String] = [], serveIndexForDirectory: Bool = true,
         redirect: Bool = true, cacheOptions: CacheOptions = CacheOptions(), acceptRanges: Bool = true,
         defaultIndex: String? = nil)

    Parameters

    possibleExtensions

    an array of file extensions to be added to the file name in case the file was not found. The extensions are added in the order they appear in the array, and a new search is performed.

    serveIndexForDirectory

    an indication whether to serve “index.html” file the requested path is a directory.

    redirect

    an indication whether to redirect to trailing “/” when the requested path is a directory.

    cacheOptions

    cache options for StaticFileServer.

    defaultIndex

    A default index, like “/index.html”, to be served if the requested path is not found. This is intended to be used by single page applications that wish to fallback to a default index when a requested path is not found, and where that path is not a file request. It will be assumed that the default index is reachable from the root directory configured with the StaticFileServer. Here’s a usage example: swift let router = Router() router.all("/", middleware: StaticFileServer(defaultIndex: "/index.html"))