how to serve static content outside the db?

隐身守侯 提交于 2019-12-11 04:04:39

问题


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


回答1:


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.)



来源:https://stackoverflow.com/questions/42657414/how-to-serve-static-content-outside-the-db

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!