View Public Assets When Run in Xcode
If you have assets in the Public
directory and you correctly configure the FileMiddleware
, Vapor should be able to serve them automatically. However, if you run your app in Xcode, you may be surprised to discover that your assets are not accessible. According to the documentation:
By default Xcode will run your project from the DerivedData folder. This folder is not the same as your project's root folder (where your Package.swift file is). This means that Vapor will not be able to find files and folders like .env or Public.
To resolve this issue, you must do the following:
- Open your project in Xcode.
- Choose Product > Scheme > Edit Scheme... (⌘<)
- Choose the Run action
- Choose the Options tab
- Choose Use custom working directory
- Input the path to your project
Afterward, your app should be able to serve Public assets when run via Xcode.