Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

152
Visualizações
fetch response not waited in sitemap module at nuxt config

I am trying to create sitemap with remote api in nuxt, but seems like promise.all not waiting for response of api and returns null object as result. I am using nuxtjs sitemap module for that job. Structure that i create at below:

import axios from 'axios'
import range from 'lodash/range'

export default {
  sitemap: {
    /**
     * ...
     */
    sitemaps: [
        /**
         * {...},
         * {...}, 
         */
        {
            path: '/mg_chapters.xml',
            /**
             * ...
             */
            sitemaps: async() => {
                const base = "https://example.com",
                    a2 = "/api/sitemap/chapters?page=";

                const fetcher = (index) =>
                    axios
                    .get(a2 + index)
                    .then((res) => res.data.data)
                    .then((els) =>
                        els.map((el) => ({
                            url: `${base}/cizgi-romanlar/${el}`,
                            /**
                             * ...
                             */
                        }))
                    );

                const sitemaps = async() => {
                    const len = await axios.get(a2 + 1).then(res => res.data.last_page)

                    return await Promise.all(
                        range(len).map(async(index) => ({
                            path: `/mg_chapters-${index + 1}.xml`,
                            routes: await fetcher(index + 1),
                            /**
                             * ...
                             */
                        }))
                    );
                }

                return await sitemaps()
            }
        }
    ]
  },
}

Weird thing is when i try this code block in async fetch() at a random vue file it works seemly, and returns expected result. Because of sitemap in nuxt.config file i can't see any error log, or what returns or not. Basically i am working on this job blindly and checking xml page. If you interested how expected result looks:

[ 
 {
   "path": "/mg_chapters-1.xml",
   "routes": [
     {
       "url": "https://example.com/cizgi-romanlar/bolum-8",
       "changefreq": "daily",
       "lastmod": "2021-11-24T14:03:55.477Z"
     }
   ],
   "cacheTime": 86400000,
   "trailingSlash": true,
   "exclude": [
     "/**"
   ]
 }
]

So, in nuxt.config, my code block returns empty and not waiting for response. As far i check this is not a limitation of sitemap module.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda