N
Nuxt9mo 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: ```js export default defineEventHandler((event) => { if (process.env.NODE_ENV === "production") { const req = event.node.req;...
Jump to solution
15 Replies
pyplacca
pyplacca9mo ago
Try clearing the app’s cache on heroku, then redeploy it
sintj_
sintj_OP9mo ago
done, no success. I leave here some more details:
sintj_
sintj_OP9mo ago
No description
No description
No description
No description
pyplacca
pyplacca9mo ago
The last url looks out of place. I’m something might be wrong with the config, but the docs also uses the same approach
sintj_
sintj_OP9mo ago
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
pyplacca
pyplacca9mo ago
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
sintj_
sintj_OP9mo ago
Turns out that the server middleware i created for SSl force is causing trouble to the sitemap:
No description
sintj_
sintj_OP9mo ago
disabling it the sitemap is generated correctly, i thought these exclude parameters were enough!
pyplacca
pyplacca9mo ago
Oh okay. What does the middleware do though? Asking out of curiosity
sintj_
sintj_OP9mo ago
it enforces https. Maybe I can achieve it differently?
pyplacca
pyplacca9mo ago
For the server api?
sintj_
sintj_OP9mo ago
nope, for the normal navigation. I did it because it didn't automatically redirect http to https when hitting the http
pyplacca
pyplacca9mo ago
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
Solution
sintj_
sintj_9mo ago
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);
}
}
});
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);
}
}
});
pyplacca
pyplacca9mo ago
That’s nice! 👍
Want results from more Discord servers?
Add your server