How do Leaf templates get into the working dir when running out of Xcode?

I'm trying out Vapor and Leaf 4. I started with trying to get a simple index.leaf template rendered as output.

One thing that's unclear to me is how the templates get "added" to the project and deployed to the output. When I just tried it, I got a JSON error structure with a message that the "index" template couldn't be found.

To get it to show up, I had to manually copy the Resources/Views folder from my project directory into the runtime working directory. I assume that is not how things are supposed to work.

Do I somehow have to declare this Resources directory somewhere to make it get copied automatically? How does this work when building for production, e.g. as a Docker image?

Yes the templates need to be copied to your deployment environment. It entirely depends how you're building and running it. If you're just doing something like a git pull and build and run from there you'll have the templates ready to go. If you're using Docker then you need to ensure that they're copied to the run image. If you're using the template's Dockerfile then below here add a similar line to copy the resources:

RUN mv /build/Resources ./Resources && chmod -R a-w ./Resources

The plan is to add Leaf support to the toolbox so this line will automatically be added if you're using Leaf

Hello there, I bumped into the same issue while also trying out Vapor for the first time and using Xcode (on Big Sur).
I did "vapor xcode" which then launched Xcode and then tried to run the app. The app lauches but when I try to connect at I get a JSON error stating that the template "index" is not found.

How can I address this issue from within the Xcode environment? I noticed that the Resources/ directory is not copied to the DerivedData directory of the build process.

You need to set a custom working directory for the project. See the docs for more details

Thank you Tim for the link!

Terms of Service

Privacy Policy

Cookie Policy