diff --git a/server/routes/api/posts.js b/server/routes/api/posts.js index 45e8c18..e7939ac 100644 --- a/server/routes/api/posts.js +++ b/server/routes/api/posts.js @@ -16,6 +16,15 @@ async function getPostCollection() { router.get('/', async (req, res) => { const posts = await getPostCollection() + if (req.query.sort === '-1' || req.query.sort === '1') { + res.send( + await posts + .find({}) + .sort({ date: parseInt(req.query.sort) }) + .toArray() + ) + return + } res.send(await posts.find({}).toArray()) })