Vapor Documentation

Class File​Middleware

public final class FileMiddleware: Middleware  

Serves static files from a public directory.

FileMiddleware will default to DirectoryConfig's working directory with "/Public" appended.

%223 FileMiddleware FileMiddleware Middleware Middleware FileMiddleware->Middleware

Conforms To


Middleware is placed between the server and your router. It is capable of mutating both incoming requests and outgoing responses. Middleware can choose to pass requests on to the next Middleware in a chain, or they can short circuit and return a custom Response if desired.



public init(publicDirectory: String, defaultFile: String? = nil)  

Creates a new FileMiddleware.


public​Directory String

The public directory to serve files from.

default​File String?

The name of the default file to look for and serve if a request hits any public directory. Starting with / implies an absolute path from the public directory root. If nil, no default files are served.



public func respond(to request: Request, chainingTo next: Responder) -> EventLoopFuture<Response>