nuxt-community / sitemap-module

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

404 error in production, working fine in dev (Nuxt 3) #237

Open skrypt-nl opened 2 years ago

skrypt-nl commented 2 years ago

First let me say that I've checked out several other issues already, but none of the following solutions posted over there works. Some of this things I tried / made sure:

As stated in the title, /sitemap.xml is working perfectly fine in dev mode (npm run dev). However, when building the site (npm run build) and starting it (nuxi preview), the site returns my 404 page. The /sitemap_style.xsl file is available in production mode. It happens both on my local device as well as on my production server (NGINX reverse proxy). My thoughts are that this is a bug with Nuxt 3, but I cannot say this with 100% certainty.

This is my nuxt.config.ts sitemap object:

sitemap: {
    xslUrl: '/sitemap_style.xsl',
    routes: async () => {
        const { data } = await axios.get('https://api.example.com') // this is the actual URL in my code, which is working
        let routes = []
        data.data.forEach((page) => {
            let route = { url: page.slug, lastmod: page.date_updated }

            routes.push(route)
        })
        return routes
    }
}
HelloAlexPan commented 2 years ago

bump, has there been any updates here? Our company is starting a fresh project on Nuxt 3 and have the capacity to help work on a Nuxt 3 build if there are any tasks that need to be completed

skrypt-nl commented 2 years ago

@HelloAlexPan no update on the issue yet unfortunately, but I downgraded my project back to Nuxt 2. Version 3 feels a little too instable and has too many small issues for a production ready site in my eyes.

desaintflorent commented 2 years ago

If anyone find a fix to this bug I would be really interested ! Hope we will be able to use Sitemap Module with Nuxt 3 soon.

dargmuesli commented 2 years ago

@NicoPennec @Atinux I'd like to apply as maintainer for this repo too. Any chance for that to happen?

pi0 commented 2 years ago

Sitemap integration with Nuxt3/Nitro needs some additional hooks to generate support that is not stable yet until we can move to use nitro pack (https://github.com/nuxt/framework/discussions/1690)

Thanks for your interest @HelloAlexPan @desaintflorent @dargmuesli to maintain repo 💚

I will try to contact the module author (@NicoPennec) to see how we can work together and support Nuxt3.

Bjornnyborg commented 2 years ago

Also experiencing this problem in this project: https://github.com/enterspeedhq/enterspeed-demo-nuxt3 Works great in dev, but throws a 404 in production: https://enterspeed-demo-nuxt3.netlify.app/sitemap.xml

Would be awesome to have this fixed! 😊

atinux commented 2 years ago

Any energy to make a PR to fix it @Bjornnyborg ?

Bjornnyborg commented 2 years ago

@Atinux Thanks for the suggestion, but i don't think i have the insights and skills necessary to make this happen. 🤔

dargmuesli commented 2 years ago

I'm not quite sure what "some additional hooks to generate support" and "until we can move to use nitro pack" mean specifically. Is something like https://github.com/nuxt-community/robots-module/pull/52 required or is there a feature to be waited for in nuxt framework? @pi0

Bjornnyborg commented 2 years ago

Since it works in develop, i would guess that the problem is something to do with not using the proper hook in nuxt3 production?

In my project i have dynamic routing controlled by Enterspeed, so i was able to just make a simple script (triggered by a build:before hook) that fetches my routes from the API and using the sitemap.js module write a sitemap.xml to the public folder.

Fy- commented 2 years ago

tmp fix: save the file in public/ and it works :')

Ahmedelforjani commented 2 years ago

is there anyone find a way to fix this bug ?

d3xter-dev commented 2 years ago

https://github.com/nuxt-community/sitemap-module/issues/248#issuecomment-1169105131