I am trying to write a server side application using Swift and Vapor environment. However, I cannot figure out how to serve static files using Vapor. It is not enough just to move them to the Public or Resources directory.
How can i do this?
UPD. I took the steps that Tanner Nelson suggested, but it still doesn't work.
What I have tried so far:
vapor build and vapor run (using Vapor Toolbox v0.6.1).
./build/debug/App from the root directory (which contains Package.swift ).
Launch in Xcode 8 beta after editing the scheme proposed by Tanner Nelson.
In all these cases, I get the error {"error":true,"message":"Page not found"}
I have a vapor_logo.png file inside the Public folder, as well as the same file inside the Public/images/ folder. I try to request it and it fails. The requests I made are: http://localhost:8080/image/vapor_logo.png and http://localhost:8080/vapor_logo.png . However, other routes work fine.
UPD 2. Well, these were all my mistakes. Firstly, the file, which I think is called vapor_logo.png , was actually called vapor-logo.png . Secondly, business matters when you make a request. I also tried to request a file named IMG_8235.JPG , but recorded the file extension as jpg , so I got an error.
So, just to repeat: if you experience the same problem as me, follow the Tanner Nelson answers and make sure that the name of the requested file exactly matches the name of the file on disk.
swift vapor
Alexander Doloz
source share