I have a Vapor server API running in Heroku supporting an iOS app. I want to create a simple landing page for my app and I would like to host it in my existing Vapor server. How could I do that?
2
votes
1 Answers
1
votes
Vapor actually has a built-in middleware that makes this very easy. First, make sure you have a Public
directory at the root of your Vapor project. Then you can put your static HTML page in there, along with any CSS and JS files it might rely on.
Next, you just need to add FileMiddleware
to your application's middleware (docs):
let file = FileMiddleware(publicDirectory: app.directory.publicDirectory)
app.middleware.use(file)
Now you can access any of the files in your Public
directory using their relative directory path as the path in the URL to your app. For example, if you have a static
directory in your Public
directory, and put a home.html
file in it, you request the page by going to http://localhost:8080/static/home.html
in your browser.