From 5968f31b9de851373f6408bcf5692fd41eba217c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A4=80=ED=9D=AC?= Date: Sun, 25 Feb 2024 01:21:55 +0900 Subject: [PATCH] =?UTF-8?q?FEAT=20:=20=EB=AC=B4=ED=95=9C=20=EC=8A=A4?= =?UTF-8?q?=ED=81=AC=EB=A1=A4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index 11007e1d..5b90ad1c 100644 --- a/server.js +++ b/server.js @@ -28,9 +28,19 @@ async function connectToMongoDB() { connectToMongoDB(); +const PAGE_SIZE = 3; + app.get('/article', async (req, res) => { + const pageNumber = req.query.pageNumber ? parseInt(req.query.pageNumber) : 1; + try { - const articles = await articleCollection.find({}).toArray(); + const articles = await articleCollection + .find({}) + .sort({ _id: -1 }) // _id를 기준으로 역순으로 정렬 + .skip((pageNumber - 1) * PAGE_SIZE) + .limit(PAGE_SIZE) + .toArray(); + res.json({ result: 'success', article: articles }); } catch (error) { console.error('Error fetching articles:', error);