mirror of
https://github.com/kevin-DL/sapper-template.git
synced 2026-01-17 20:34:53 +00:00
20 lines
373 B
JavaScript
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);
|
|
} |