nuxt-community / sitemap-module

Sitemap Module for Nuxt 2
https://sitemap.nuxtjs.org
MIT License
689 stars 127 forks source link

400 error on production mode #229

Open S-Masoud-Emamian opened 2 years ago

S-Masoud-Emamian commented 2 years ago

On developer mode everything work fine. The request with axios library is sent well. but on production mode my request show a 400 status code.

inside my nuxt.config.js:

    sitemap: {
        hostname: process.env.BASE_URL,
        zip: true,
        i18n: {
            locales: ['en', 'fa'],
            routesNameSeparator: '___'
        },
        defaults: {
            changefreq: 'daily',
            priority: 1,
            lastmod: new Date()
        },
        sitemaps: [
            {
                path: '/fa/sitemap/products.xml',
                routes: async () => {
                    const URL = `${process.env.API_URL}${process.env.API_PREFIX}`;
                    const products = await axios.get(`${URL}/sitemap?query=products`, {
                        headers: {locale: 'fa'}
                    }).then(r => r && r.data.result);

                    return products.map((product) => {
                        return {
                            url: `/fa/product/${product.id}/${decodeURIComponent(product.slug)}`,
                            changefreq: 'daily',
                            priority: 1,
                            lastmod: product.last_modified_at
                        }
                    });
                },
                exclude: ['/**']
            },
            {
                path: '/en/sitemap/products.xml',
                routes: async () => {
                    const URL = `${process.env.API_URL}${process.env.API_PREFIX}`;
                    const products = await axios.get(`${URL}/sitemap?query=products`, {
                        headers: {locale: 'en'}
                    }).then(r => r && r.data.result);

                    return products.map((product) => {
                        return {
                            url: `/fa/product/${product.id}/${decodeURIComponent(product.slug)}`,
                            changefreq: 'daily',
                            priority: 1,
                            lastmod: product.last_modified_at
                        }
                    });
                },
                exclude: ['/**']
            },

            {
                path: '/fa/sitemap/categories.xml',
                routes: async () => {
                    const URL = `${process.env.API_URL}${process.env.API_PREFIX}`;
                    const categories = await axios.get(`${URL}/sitemap?query=categories`, {
                        headers: {locale: 'fa'}
                    }).then(r => r && r.data.result);

                    return categories.map((category) => {
                        return {
                            url: `/fa/search?categoryId=${category.id}`,
                            changefreq: 'daily',
                            priority: 1,
                            lastmod: category.last_modified_at
                        }
                    });
                },
                exclude: ['/**']
            },
            {
                path: '/en/sitemap/categories.xml',
                routes: async () => {
                    const URL = `${process.env.API_URL}${process.env.API_PREFIX}`;
                    const categories = await axios.get(`${URL}/sitemap?query=categories`, {
                        headers: {locale: 'en'}
                    }).then(r => r && r.data.result);

                    return categories.map((category) => {
                        return {
                            url: `/en/search?categoryId=${category.id}`,
                            changefreq: 'daily',
                            priority: 1,
                            lastmod: category.last_modified_at
                        }
                    });
                },
                exclude: ['/**']
            },

            {
                path: '/en/sitemap/pages.xml',
                routes: async () => {
                    const URL = `${process.env.API_URL}${process.env.API_PREFIX}`;
                    const pages = await axios.get(`${URL}/sitemap?query=pages`, {
                        headers: {locale: 'en'}
                    }).then(r => r && r.data.result);

                    return [
                        ...pages.map((page) => {
                            return {
                                url: `/en/pages/${decodeURI(page.slug)}`,
                                changefreq: 'daily',
                                priority: 1,
                                lastmod: page.last_modified_at
                            }
                        }),
                        ...[{
                            url: '/fa/pages/contact-us',
                            changefreq: 'daily',
                            priority: 1,
                        }]
                    ]
                },
                exclude: ['/**']
            },
            {
                path: '/fa/sitemap/pages.xml',
                routes: async () => {
                    const URL = `${process.env.API_URL}${process.env.API_PREFIX}`;
                    const pages = await axios.get(`${URL}/sitemap?query=pages`, {
                        headers: {locale: 'fa'}
                    }).then(r => r && r.data.result);

                    return [
                        ...pages.map((page) => {
                            return {
                                url: `/fa/pages/${page.slug}`,
                                changefreq: 'daily',
                                priority: 1,
                                lastmod: page.last_modified_at
                            }
                        }),
                        ...[{
                            url: '/fa/pages/contact-us',
                            changefreq: 'daily',
                            priority: 1,
                        }]
                    ];
                },
                exclude: ['/**']
            }
        ]
    },

output on production:

Request failed with status code 400                                                                                                               
at createError (node_modules/axios/lib/core/createError.js:16:15)                                                                                 at settle (node_modules/axios/lib/core/settle.js:17:12)                                                                                           at IncomingMessage.handleStreamEnd (node_modules/axios/lib/adapters/http.js:260:11)                                                               at IncomingMessage.emit (events.js:388:22)                                                                                                        at IncomingMessage.emit (domain.js:532:15)                                                                                                        at endReadableNT (internal/streams/readable.js:1336:12)                                                                                           at processTicksAndRejections (internal/process/task_queues.js:82:21)