Reputation: 9830
I'm trying to add a sitemap to my next.js website. I added the following code to server.js
server.get('/sitemap.xml', (req, res) => {
const options = {
root:'./',
headers: {
'Content-Type': 'text/plain;charset=UTF-8',
}
};
return res.status(200).sendFile('sitemap.xml', options)
});
The sitemap.xml
file is at the root folder, i.e. the same location as the server.js
file. When I run it locally using node server
, and go to http://localhost:5000/sitemap.xml
it works correctly. When I upload the files to the server, I get a not found
error from the server.
What am I doing wrong, and how can I add a sitemap using nextjs?
Upvotes: 1
Views: 2151
Reputation: 13655
Probably just move the sitemap.xml
file under the public folder such as public/sitemap.xml
and then delete this custom dynamic route.
Next.js static file serving documentation
Upvotes: 2