replace Express shorthands w/ native counterparts

This commit is contained in:
Luke Edwards
2018-01-19 13:54:55 -08:00
parent a6dc61a182
commit f4e46e6e6c

View File

@@ -120,10 +120,9 @@ function get_asset_handler(opts) {
return (req, res, next) => { return (req, res, next) => {
if (!opts.filter(req.pathname)) return next(); if (!opts.filter(req.pathname)) return next();
res.set({ res.setHeader('Content-Type', opts.type);
'Content-Type': opts.type, res.setHeader('Cache-Control', opts.cache);
'Cache-Control': opts.cache
});
res.end(opts.fn(req.pathname)); res.end(opts.fn(req.pathname));
}; };
} }
@@ -139,7 +138,7 @@ function get_route_handler(fn) {
if (route.type === 'page') { if (route.type === 'page') {
// preload main.js and current route // preload main.js and current route
// TODO detect other stuff we can preload? images, CSS, fonts? // TODO detect other stuff we can preload? images, CSS, fonts?
res.set('Link', `<${client.main_file}>;rel="preload";as="script", <${client.routes[route.id]}>;rel="preload";as="script"`); res.setHeader('Link', `<${client.main_file}>;rel="preload";as="script", <${client.routes[route.id]}>;rel="preload";as="script"`);
const data = { params: req.params, query: req.query }; const data = { params: req.params, query: req.query };
@@ -198,9 +197,7 @@ function get_route_handler(fn) {
const url = req.pathname; const url = req.pathname;
// whatever happens, we're going to serve some HTML // whatever happens, we're going to serve some HTML
res.set({ res.setHeader('Content-Type', 'text/html');
'Content-Type': 'text/html'
});
resolved resolved
.then(() => { .then(() => {
@@ -212,7 +209,7 @@ function get_route_handler(fn) {
next(); next();
}) })
.catch(err => { .catch(err => {
res.status(500); res.statusCode = 500;
res.end(templates.render(500, { res.end(templates.render(500, {
title: (err && err.name) || 'Internal server error', title: (err && err.name) || 'Internal server error',
url, url,
@@ -227,7 +224,7 @@ function get_not_found_handler(fn) {
return function handle_not_found(req, res) { return function handle_not_found(req, res) {
const asset_cache = fn(); const asset_cache = fn();
res.status(404); res.statusCode = 404;
res.end(templates.render(404, { res.end(templates.render(404, {
title: 'Not found', title: 'Not found',
status: 404, status: 404,