2

I'm trying to figure out how to push static files, like an svg or an image, in a module without having to put it in the db. I've created a simple module that define a route with self.apos.app.get and with pushAssets I send js and css to render a template, but how to serve an image or svg defined in the css? I can put them in prj_root/public but I'm unsure if this is the way to do it. I've tried to put in my_module/public but they are not found

diramazioni
  • 174
  • 9

1 Answers1

2

If you put a file called my.png in /public/images/my.png, then it becomes accessible as /images/my.png. This is because Apostrophe sets up the express.static middleware for the /public folder.

If you put a file called my.png in lib/modules/mymodule/public/my.png, it becomes accessible as /modules/mymodule/my.png. This is because Apostrophe establishes symbolic links from each module's /public folder in /public/modules.

(When running on Windows, Apostrophe copies the files there at startup instead, and for a tiny performance boost we may eventually do that in production for Linux too, but either way the result is the same.)

Tom Boutell
  • 7,281
  • 1
  • 26
  • 23