NextJS动态站点地图无法在生产服务器上工作

发布于 2025-02-09 14:04:50 字数 900 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文