Is it possible to serve dynamic sitemap on each new request? #73814
Answered
by
icyJoseph
BakirGracic
asked this question in
Help
-
SummaryI need my sitemap to fetch up-to-date data and use it on each request, not only on build-time! I tried to utilize the Dynamic API with server components but got:
I wanted to find out here if this was even available before creating any issues Make sure to check the example code Additional informationEDIT: NextJS v 15.1.0 w/ clean setup Exampleimport type { MetadataRoute } from 'next';
export default async function Sitemap(): Promise<MetadataRoute.Sitemap> {
const users = await fetch(`${process.env.API_URL}/users/list`).then((res) => res.json());
const usersRoutes = users.map((user: { slug: string }) => ({
url: `${process.env.APP_URL}/user/${user.slug}`,
lastModified: new Date(),
changeFrequency: 'monthly',
priority: 0.8,
}));
return [
{
url: `${process.env.APP_URL}`,
lastModified: new Date(),
changeFrequency: 'monthly',
priority: 1,
},
...usersRoutes,
];
} |
Beta Was this translation helpful? Give feedback.
Answered by
icyJoseph
Dec 11, 2024
Replies: 1 comment 1 reply
-
Shouldn't you be able to add |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
BakirGracic
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shouldn't you be able to add
export const dynamic = 'force-dynamic'
?