mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-16 04:44:35 +00:00
23 lines
446 B
JavaScript
23 lines
446 B
JavaScript
import posts from './_posts.js';
|
|
|
|
const lookup = {};
|
|
posts.forEach(post => {
|
|
lookup[post.slug] = JSON.stringify(post);
|
|
});
|
|
|
|
export function get(req, res, next) {
|
|
// the `slug` parameter is available because this file
|
|
// is called [slug].js
|
|
const { slug } = req.params;
|
|
|
|
if (slug in lookup) {
|
|
res.writeHead(200, {
|
|
'Content-Type': 'application/json',
|
|
'Cache-Control': `no-cache`
|
|
});
|
|
|
|
res.end(lookup[slug]);
|
|
} else {
|
|
next();
|
|
}
|
|
} |