mirror of
https://github.com/kevin-DL/sapper-template.git
synced 2026-01-21 05:55:03 +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';
|
import posts from './_posts.js';
|
||||||
|
|
||||||
const lookup = {};
|
const lookup = new Map();
|
||||||
posts.forEach(post => {
|
posts.forEach(post => {
|
||||||
lookup[post.slug] = JSON.stringify(post);
|
lookup.set(post.slug, JSON.stringify(post));
|
||||||
});
|
});
|
||||||
|
|
||||||
export function get(req, res, next) {
|
export function get(req, res, next) {
|
||||||
@@ -10,13 +10,13 @@ export function get(req, res, next) {
|
|||||||
// is called [slug].js
|
// is called [slug].js
|
||||||
const { slug } = req.params;
|
const { slug } = req.params;
|
||||||
|
|
||||||
if (slug in lookup) {
|
if (lookup.has(slug)) {
|
||||||
res.set({
|
res.set({
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Cache-Control': `max-age=${30 * 60 * 1e3}` // cache for 30 minutes
|
'Cache-Control': `max-age=${30 * 60 * 1e3}` // cache for 30 minutes
|
||||||
});
|
});
|
||||||
|
|
||||||
res.end(lookup[slug]);
|
res.end(lookup.get(slug));
|
||||||
} else {
|
} else {
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user