mirror of
https://github.com/kevin-DL/sapper-template.git
synced 2026-01-12 10:25:16 +00:00
Merge pull request #15 from mathiasbynens/map
Use a map for the lookup table
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import posts from './_posts.js';
|
||||
|
||||
const lookup = {};
|
||||
const lookup = new Map();
|
||||
posts.forEach(post => {
|
||||
lookup[post.slug] = JSON.stringify(post);
|
||||
lookup.set(post.slug, JSON.stringify(post));
|
||||
});
|
||||
|
||||
export function get(req, res, next) {
|
||||
@@ -10,14 +10,14 @@ export function get(req, res, next) {
|
||||
// is called [slug].js
|
||||
const { slug } = req.params;
|
||||
|
||||
if (slug in lookup) {
|
||||
if (lookup.has(slug)) {
|
||||
res.set({
|
||||
'Content-Type': 'application/json',
|
||||
'Cache-Control': `max-age=${30 * 60 * 1e3}` // cache for 30 minutes
|
||||
});
|
||||
|
||||
res.end(lookup[slug]);
|
||||
res.end(lookup.get(slug));
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user