NextJS动态站点地图无法在生产服务器上工作
NextJS动态站点地图在Localhost上工作,但在生产服务器上遇到了500个内部服务器错误。该URL在http:// localhost:3000/server-sitemap.xml上使用=“ nofollow noreferrer”> https://www.example.com/server-sitemap.xml
这是我的代码: 我的index.tsx文件夹结构是页面> server-sitemap.xml> index.tsx
index.tsx
import { GetServerSideProps } from "next";
import { getServerSideSitemap, ISitemapField } from "next-sitemap";
export const getServerSideProps: GetServerSideProps = async (ctx) => {
const response = await fetch("https://backendapi.example.com/blog-list/");
const data: any[] = await response.json();
const fields: ISitemapField[] = data.map((blog) => ({
loc: `https://www.example.com/blog/${(blog.blog_slug)}`,
lastmod: new Date().toISOString(),
}));
return getServerSideSitemap(ctx, fields);
};
export default function Site() {}
Nextjs dynamic sitemaps working on localhost but getting 500 Internal Server Error on production server. This url worked on http://localhost:3000/server-sitemap.xml but I am not understanding why it's not working on production https://www.example.com/server-sitemap.xml
here is my code:
my index.tsx folder structure is pages>server-sitemap.xml>index.tsx
index.tsx
import { GetServerSideProps } from "next";
import { getServerSideSitemap, ISitemapField } from "next-sitemap";
export const getServerSideProps: GetServerSideProps = async (ctx) => {
const response = await fetch("https://backendapi.example.com/blog-list/");
const data: any[] = await response.json();
const fields: ISitemapField[] = data.map((blog) => ({
loc: `https://www.example.com/blog/${(blog.blog_slug)}`,
lastmod: new Date().toISOString(),
}));
return getServerSideSitemap(ctx, fields);
};
export default function Site() {}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论