Open aenachetruebase opened 1 year ago
Interesting approach.
VPS has a bunch of internal assumptions that don't allow you to do that. That said, you can workaround the issue by spinning off a second/background Node.js process. It's not only a workaround but also a performance improvement: your server shouldn't be slowed down by the pre-rendering job. (Also, the pre-rendering process isn't optimized to be run within a long-running process, e.g. it may have memory leaks.)
Let me know whether that workaround works out for you.
Thanks for the workaround suggestion! I will look into it and come back with an answer. This is mainly because we're updating our CMS on a weekly(ish) basis but I would like for the content team to be able to start the prerender process when needed / when content changed without needing to re-deploy.
Makes sense.
Btw. I'm considering turning the workaround into an official & well-polished VPS feature.
Also check out vite-plugin-vercel which supports ISR, see https://vite-plugin-ssr.com/vercel#vite-plugin-vercel.
Curious: what made you go for your current deployment strategy instead of only pre-rendering? (I guess you're already familiar with Should I pre-render?)
That sounds great!
We're using heroku right now so we can't use the vercel plugin sadly.
I thought that it makes most sense to have something that provides SEO but can be revalidated on-demand and without the need to rebuild and redeploy; I also thought of the prerender as an extra performance optimization on top of SSR.
If doing pre-rendering only is an option (i.e. without using SSR) then I'd recommend doing that.
Right now it's not an option for us, sadly; It would mean having to redeploy whenever something in the CMS changes and that's too complex for our current workflow.
I'll play around with the triggering of the prerender on a child process of the server - it sounds like a great enhancement idea if it would be provided as an option of VPS, for sure.
👍 Keep me updated.
Back with updates: Tried using exec to spawn a child process to run the prerender function
exec('node ./server/revalidate.js', (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
});
revalidate.js
const { prerender } = require('vite-plugin-ssr/prerender');
(async () => {
try {
await prerender();
} catch (e) {
console.log(e);
return e;
}
})();
And everything works as expected!
Great workaround, thank you so much!
👍 I'm glad it worked out. Btw. in case your company is up for it: https://github.com/sponsors/brillout – sponsoring is starting to make a big impact on VPS.
Description
Defined a server route like this:
Calling into that route returns this message:
Error Message + Error Stack