Digging Deeper
File Storage
Serving Static Files
If you’d like to serve files from a static directory, there’s a Middleware
for that. It will match incoming requests to files in the directory, streaming those back to the client if they exist. By default, it serves from Public/
but you may pass a custom path in the initializer if you like.
Consider a Public
directory in your project with a few files.
You could use the following code to serve files from that directory.
Now, assets in the Public/
directory can be requested.
Note: The given directory is relative to your server’s working directory. If you are using Xcode, be sure to set a custom working directory for your project where the static file directory is.