diff --git a/server/routes/api/posts.js b/server/routes/api/posts.js
index 835529a..6080231 100644
--- a/server/routes/api/posts.js
+++ b/server/routes/api/posts.js
@@ -56,4 +56,25 @@ routes.set('/:id', async (req, res) => {
else res.send(results[0])
})
+// For the sitemap.xml, will be listed in the XML Sitemap Index
+routes.set('/urls', async (req, res) => {
+ const re = /(\/api\/)?(.*)\/urls/g
+ const result = [...req.raw.originalUrl.matchAll(re)]
+ if (!result) notFoundResponse(res)
+ const endpoint = result [1] ? result[1][2] : result[0][2]
+ // Assumes https
+ const BASE_URL = 'https://' + req.raw.hostname + endpoint
+ const urls = posts.map(post =>
+ `\n
+ ${BASE_URL}/${post._id}
+ ${post.date}
+ never
+ 0.9
+ `
+ ).join("\n")
+ const xml = `\r
+ ${urls}\n\r`
+ res.send(xml)
+})
+
module.exports = routes