Files
sapper-template/routes/blog/index.json.js
2018-07-27 14:28:32 -04:00

20 lines
373 B
JavaScript

import { getPosts } from './_posts.js';
let contents;
export function get(req, res) {
if (!contents || process.env.NODE_ENV !== 'production') {
const posts = getPosts().map(post => ({
title: post.metadata.title,
slug: post.slug
}));
contents = JSON.stringify(posts);
}
res.writeHead(200, {
'Content-Type': 'application/json'
});
res.end(contents);
}