StaticFileServer
open class StaticFileServer : RouterMiddleware
A router middleware that serves static files from a given path. By default, it will serve files from the “/public” directory.
Usage Example:
The example below creates and registers a StaticFileServer on the “/example” route.
When the router is running, A user can make a request that matches the “/example” path (e.g. localhost:8080/example/hello.html).
The static file server would look inside its “/files” folder for a file with the same name as the path following “/example” (e.g. “hello.html”).
If a file is found it is sent as a response to that request, otherwise the next handler is called.
let router = Router()
router.all("/example", middleware: StaticFileServer(path: "./files"))
-
Cache configuration options for StaticFileServer.
See moreDeclaration
Swift
public struct CacheOptions -
Configuration options for StaticFileServer.
See moreDeclaration
Swift
public struct Options -
The absolute (fully qualified) root serving path for this
StaticFileServer, for example:/Users/Dave/MyKituraProj/./publicDeclaration
Swift
public let absoluteRootPath: String
-
Initializes a
StaticFileServerinstance.Declaration
Swift
public init(path: String = "./public", options: Options = Options(), customResponseHeadersSetter: ResponseHeadersSetter? = nil)Parameters
patha root directory for file serving.
optionsconfiguration options for StaticFileServer.
customResponseHeadersSetteran object of a class that implements
ResponseHeadersSetterprotocol providing a custom method to set the headers of the response.
-
Handle the request - serve static file.
Declaration
Swift
open func handle(request: RouterRequest, response: RouterResponse, next: @escaping () -> Void)Parameters
requestThe
RouterRequestobject used to work with the incoming HTTP request.responseThe
RouterResponseobject used to respond to the HTTP request.nextThe closure called to invoke the next handler or middleware associated with the request.
View on GitHub
StaticFileServer Class Reference