updated to make index page working
This commit is contained in:
1 parent
7363d7c0ec
commit
5831275b7a
11 files changed
+160
-149
No files matched your search
@@ -1,21 +0,0 @@
|
||||
// import { findArticles } from '../../../src/api/articles'
|
||||
import { withMiddleware } from '../../../src/middlewares/withMiddleware'
|
||||
import Article from '../../../src/core/Article'
|
||||
|
||||
export default withMiddleware(async (req, res) => {
|
||||
// const { query } = req
|
||||
// const page = parseInt(query.page)
|
||||
// const pageSize = parseInt(query.pageSize)
|
||||
|
||||
// const data = await findArticles(page, pageSize)
|
||||
const data = await Article.find({})
|
||||
|
||||
if (data) {
|
||||
res.json(data)
|
||||
} else {
|
||||
res.status(404)
|
||||
res.json({
|
||||
error: `Article ${id} not found`
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,19 @@
|
||||
import { findArticles } from '../../../src/server/articles'
|
||||
import { withMiddleware } from '../../../src/middlewares/withMiddleware'
|
||||
|
||||
export default withMiddleware(async (req, res) => {
|
||||
const { query } = req
|
||||
const page = parseInt(query.page)
|
||||
const pageSize = parseInt(query.pageSize)
|
||||
|
||||
const data = await findArticles(page, pageSize)
|
||||
|
||||
if (data) {
|
||||
res.json(data)
|
||||
} else {
|
||||
res.status(404)
|
||||
res.json({
|
||||
error: `Articles not found`
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in new issue
Block a user