Files
hudozka/pages/api/articles/[article].js
T
2019-08-03 00:26:27 +03:00

23 lines
497 B
JavaScript

import { connect } from '../../../src/core/db'
import Article from '../../../src/core/Article'
import { encodeArticle } from '../../../src/api/articles'
export default async (req, res) => {
await connect()
const {
query: { article: id }
} = req;
const article = await Article.findById(id)
if (article) {
res.json(encodeArticle(article))
} else {
res.status(404)
res.json({
error: `Article ${id} not found`
})
}
}