mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-14 18:01:06 +00:00
21 lines
553 B
JavaScript
21 lines
553 B
JavaScript
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.writeHead(200, { "Content-Type": "application/json" });
|
|
res.end(lookup.get(slug));
|
|
} else {
|
|
res.writeHead(404, { "Content-Type": "application/json" });
|
|
res.end(JSON.stringify({ message: `Not found` }));
|
|
}
|
|
}
|