#@nuxtjs/sitemap won't generate the dynamic URLs in production

1 messages · Page 1 of 1 (latest)

past pine
#

Hi, i'm using nuxtjs/sitemap module and i set up under server/api/sitemap/urls.ts the logic to retrieve all my dynamic urls (it's an ecommerce). When running npm run dev i see everything ok, in the sitemap there are over 600 link product urls. But when pushing and hitting the sitemap in production I only see the static pages i created. Can somebody help me? The app is on Heroku

dim stirrup
#

Try clearing the app’s cache on heroku, then redeploy it

past pine
dim stirrup
# past pine

The last url looks out of place. I’m something might be wrong with the config, but the docs also uses the same approach

past pine
#

well, i indeed followed the official docs. Yeah and i don't know why the url of the api gets printed in the production sitemap. I don't really get what's wrong here

dim stirrup
#

I haven’t actually used @nuxtjs/sitemap before so I’d have try it out on my end to be able to further assist. For what I’ve used, clearing cache and redeploying usually solves the problem

past pine
#

Turns out that the server middleware i created for SSl force is causing trouble to the sitemap:

#

disabling it the sitemap is generated correctly, i thought these exclude parameters were enough!

dim stirrup
#

Oh okay. What does the middleware do though? Asking out of curiosity

past pine
#

it enforces https. Maybe I can achieve it differently?

dim stirrup
past pine
#

nope, for the normal navigation. I did it because it didn't automatically redirect http to https when hitting the http

dim stirrup
#

I see. Isn’t this usually handled by the deployment platform? Netlify and Digital Ocean for instance automatically redirect to https if you enter http

past pine
#

Yea I was used to it on Netlify but on Heroku it didn't seem like it. Anyway I managed to make it work editing the middleware like this:

export default defineEventHandler((event) => {
  if (process.env.NODE_ENV === "production") {
    const req = event.node.req;
    const proto =
      req.headers["x-forwarded-proto"] || "http";

    if (
      proto !== "https" &&
      !req.headers.host?.includes("localhost")
    ) {
      const httpsUrl = `https://${req.headers.host}${req.url}`;
      return sendRedirect(event, httpsUrl, 301);
    }
  }
});
dim stirrup
#

That’s nice! 👍