switch to [slug].json.js server routes, instead of /api/...

This commit is contained in:
Rich Harris
2018-03-03 21:39:28 -05:00
parent e5d3589b63
commit 6a286f470d
5 changed files with 5 additions and 5 deletions

View File

@@ -0,0 +1,22 @@
import posts from './_posts.js';
const lookup = new Map();
posts.forEach(post => {
lookup.set(post.slug, JSON.stringify(post));
});
export function get(req, res, next) {
// the `slug` parameter is available because this file
// is called [slug].json.js
const { slug } = req.params;
if (lookup.has(slug)) {
res.set({
'Content-Type': 'application/json'
});
res.end(lookup.get(slug));
} else {
next();
}
}