Files
mip-website/pages/api/my-sitemap.js
T

25 lines
766 B
JavaScript
Raw Normal View History

2023-07-12 15:37:34 +03:30
const { SitemapStream, streamToPromise } = require("sitemap");
const { Readable } = require("stream");
export default async (req, res) => {
// An array with your links
const links = [
{ url: "/page/news/36/", priority: 0.3 },
{ url: "/page/about", priority: 0.3 },
{ url: "/recruitment", priority: 0.3 },
{ url: "/contact-us", priority: 0.3 }
];
// Create a stream to write to
const stream = new SitemapStream({ hostname: `https://${req.headers.host}` });
res.writeHead(200, {
"Content-Type": "application/xml",
});
const xmlString = await streamToPromise(
Readable.from(links).pipe(stream)
).then((data) => data.toString());
res.end(xmlString);
2023-01-04 08:47:19 +03:30
};