I'd like to serve some static files from a Snaplet in the Snap framework. How do I do that? The documentation is not exactly clear.
I know how to add routes and stuff, but I'm stuck at two problems:
serveDirectory to serve files from the snaplet directory?Yes, serveDirectory is what you would use to serve static files. You might have a route like this:
route [("static", serveDirectory "myDir"), ...]
When you reference those files in templates, you have to use the route that you assigned. So if you had a file myDir/foo.js, then in a template, you'd refer to it with /static/foo.js.
If you don't know your snaplet's base URL, you can get it with the getSnapletRootURL function. Then you can make that available in your templates with a Heist splice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With