[Vuejs]-Nuxt Sitemap not updating in SSR mode

0👍

I went and did a more thorough look through the documentation after reading some of the comments and saw I had made a mistake. I moved my api call onto the routes property, like in the following link, and my code started working:

https://sitemap.nuxtjs.org/usage/sitemap-options#from-a-function-which-returns-a-promise

sitemap() {
        return {
            cacheTime: 1000 * 60 * 15, // 15 minutes
            hostname: 'www.foo.bar',
            gzip: true,
            exclude: [
                //...
            ],
            routes: async () => {
                const articleRoutes = [];
                const now = new Date();
                await axios
                    .get(ARTICLES_URL)
                    .then((response) => {
                        response.data.data.forEach((route) => {
                            const publishDate = new Date(route.publish_date);
                            if (publishDate < now) articleRoutes.push(`/${route.id}`);
                        });
                    })
                    .catch((error) => {
                        throw new Error(error);
                    });
          return articleRoutes;
            },
        };

It now seems to work and automatically rebuilds the sitemap as the documentation suggests.

Leave a comment