nuxt-community / sitemap-module

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

Sitemap module not working properly with a custom `publicPath` #204

Closed jlefebvre1997 closed 3 years ago

jlefebvre1997 commented 3 years ago

Version

2.4.0

Reproduction link

https://codesandbox.io/s/gallant-pascal-dox5n?file=/nuxt.config.js

Steps to reproduce

just run yarn dev and access /sitemap.xml on the codesandbox repo.

What is expected ?

The sitemap should be displayed in XML format

What is actually happening?

A Nuxt error shows up : "invalid URL : /static/_nuxt"

Additional comments?

Linked to this issue : https://github.com/nuxt-community/sitemap-module/issues/60 A solution has been provided in this issue : explicitely set "hostname" in sitemap config. However, it is not possible in my case, as my project will be hosted on several environments, and hostname won't be the same for each environment. I would have to access the current hostname in "nuxt.config.js" but I don't think this is possible.

This bug report is available on Nuxt community (#c141)
jlefebvre1997 commented 3 years ago

I managed to fix it by setting hostname to null, as the module fallbacks to req.headers.host in this case.