Skip to content

Commit

Permalink
FEAT : 무한 스크롤 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
junvhui committed Feb 24, 2024
1 parent e238e74 commit 3667eca
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,26 @@ 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({})
.sort({ _id: -1 }) // _id를 기준으로 역순으로 정렬
.skip((pageNumber - 1) * PAGE_SIZE)
.limit(PAGE_SIZE)
.toArray();

const articles = await articleCollection.find({}).toArray();
res.json({ result: 'success', article: articles });
} catch (error) {
console.error('Error fetching articles:', error);
res.status(500).json({ result: 'error', message: 'Internal server error' });
}
});

app.get('/rank', async (req, res) => {
try {
const ranks = await rankCollection.find({}).toArray();
res.json({ result: 'success', rank: ranks });
} catch (error) {
console.error('Error fetching ranks:', error);
res.status(500).json({ result: 'error', message: 'Internal server error' });
}
});

app.get('/transfer', async (req, res) => {
try {
const transfers = await transferCollection.find({}).toArray();
Expand Down

0 comments on commit 3667eca

Please sign in to comment.