Oscar
Oscar

Reputation: 23

Error on generate sitemap.xml -> dynamicRoutes.map is not a function

Context:

I'm using Nuxt Sitemap Module and I'm trying to generate or create my dynamics routes (products that i have on my DB). Here is my sitemap on my nuxt.config.js

sitemap: {
    hostname: process.env.PH_WEB_APP_BASE_URL || 'http://localhost:3000/',
    gzip: true,
    exclude: ExcludedPaths,
    cacheTime: 1000 * 60 * 15,
    defaults: {
      changefreq: 'daily',
      priority: 1,
      lastmod: new Date()
    },
    routes: () => {
      const baseUrl = process.env.PH_WEB_APP_BASE_URL || 'http://localhost:3000/';
      return axios.get(`${baseUrl}api/sitemap-slugs/`);
    }
  },

The endpoint ${baseUrl}api/sitemap-slugs/ returns an array of slugs ['slug1','slug2']

Expected Result

My sitemap.xml page with all my statics routes and my dynamic routes.

ERROR

Error on my http://localhost:3000/sitemap.xml. enter image description here

I hope I have explained the situation and myself well

Upvotes: 1

Views: 1394

Answers (1)

pmalecki
pmalecki

Reputation: 229

I had the same issue. You have to use data property of axios response if it returns string array.

routes: async () => {
      const result = await axios.get('https://www.example.com/api/blog-sitemap')
      return result.data;
 }

Upvotes: 2

Related Questions