sailsjs generate dynamic views/ejs files

2019-09-03 09:37发布

问题:

I'm generating/copying ejs files dynamically and put them in views folder and they work fine in development mode however in production mode it's not reflecting changes until I relaunch sails. How can I make it work in production mode as well?

I'm using simple fs create/update file operations to write to ejs file

回答1:

Found the solution. Following posts helped me in that:

Sailsjs view caching (bug ?)

https://github.com/balderdashy/sails/issues/3513

http://expressjs.com/en/api.html

The reason is, express was cashing views in production mode, so on disabling that it worked.

sails.hooks.http.app.disable('view cache');
console.log("view-cache-disabled: " + sails.hooks.http.app.disabled("view cache"));


回答2:

You have to use a watcher like forever, nodemon, or something else...

Install forever by running:

sudo npm install -g forever

Run it:

forever -w start app.js


标签: sails.js ejs