Create post api

This commit is contained in:
LordMathis 2017-11-07 18:17:44 +01:00
parent 8121a1917b
commit e5016c9fb1
1 changed files with 20 additions and 2 deletions

View File

@ -1,7 +1,25 @@
const data = require('./data.json'); const data = require('./data.json');
module.exports = function(app) { module.exports = function(app) {
app.get('/api/blog', ((req, res) => { app.get('/api/blog', (req, res) => {
res.json(data.posts); res.json(data.posts);
})); });
app.get('api/post/:postname', (req, res) => {
const post = data.posts.find((el) => {
el.filename === req.params.postname
});
if (post) {
res.json(post);
} else {
res.json({
error: 404
});
}
})
}
function (postname) {
data.posts
} }