forked from kriasoft/react-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery.js
More file actions
29 lines (21 loc) · 614 Bytes
/
query.js
File metadata and controls
29 lines (21 loc) · 614 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*! React Starter Kit | MIT License | http://www.reactstarterkit.com/ */
import { Router } from 'express';
import db from '../core/Database';
const router = new Router();
router.get('/', async (req, res, next) => {
try {
let path = req.query.path;
if (!path) {
res.status(400).send({error: `The 'path' query parameter cannot be empty.`});
}
let page = await db.getPage(path);
if (page) {
res.status(200).send(page);
} else {
res.status(404).send({error: `The page '${path}' is not found.`});
}
} catch (err) {
next(err);
}
});
export default router;