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

Terms of Service

Privacy Policy

Cookie Policy