NuxtN
Nuxt2y ago
sintj_

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

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
Solution
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);
    }
  }
});
Was this page helpful?