I'm trying to write server side application using Swift and Vapor framework. However, I can't figure out, how to serve static files using Vapor. It's not enough to just move them to the Public
or Resources
directory.
How can I do that?
UPD. I performed steps which Tanner Nelson suggested but it still doesn't work.
What I tried so far:
vapor build
andvapor run
(using Vapor Toolbox v0.6.1)../build/debug/App
from root directory (which containsPackage.swift
).Run in Xcode 8 beta after editing scheme as Tanner Nelson suggested.
In all this cases I get error
{"error":true,"message":"Page not found"}
I have file vapor_logo.png
inside a Public
folder and also the same file inside Public/images/
folder. I try to request it and it fails. Requests that I made: http://localhost:8080/image/vapor_logo.png
and http://localhost:8080/vapor_logo.png
. However, other routes work fine.
UPD 2. Well, that was all my mistakes. First, file that I think was called vapor_logo.png
, actually was called vapor-logo.png
. Second, case matters when you make a request. I also tried to request file with name IMG_8235.JPG
but write file extension as jpg
, so got an error.
So, just to recap: if you experience the same problem as me, follow the Tanner Nelson's answer and make sure that name of requested file exactly matches name of file on disk.