Hi everyone,
Even though I look in some old posts I did not find a solution for my issue so I am creating a new post.
I am generating a Sitemap.xml dynamically. So far I am serving it live with a route using Webapp. While it works I don’t like that it takes quite a lot of ressources to go through the Collections all the time to generate the new sitemap and could be an easy way for my site to be slow if for some reason someone would permanently generate a sitemap.
So I am looking to save the file to the public folder using fs but so far couldn’t make it work. I never manage to find a way to access properly the path that would work both for development and production. I am following this tutorial : https://thedutchlab.com/blog/generating-a-sitemapxmlgz-every-night but I can’t manage to have this line work:
fs.writeFileSync(require('path').resolve(__dirname,'../public/sitemap.xml'), sitemap.toString());
The path is never good. I could have it work once in development bu then it failed in production. the code was the following:
const path = process.env["METEOR_SHELL_DIR"] + "/../../../public/sitemap.xml";
fs.writeFileSync(path, sitemap.toString());
but in prod the path was the following:
path: 'undefined/../../../public/sitemap.xml'
Thanks in advance for your support.