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) => {
if (!opts.filter(req.pathname)) return next();
res.set({
'Content-Type': opts.type,
'Cache-Control': opts.cache
});
res.setHeader('Content-Type', opts.type);
res.setHeader('Cache-Control', opts.cache);
res.end(opts.fn(req.pathname));
};
}
@@ -139,7 +138,7 @@ function get_route_handler(fn) {
if (route.type === 'page') {
// preload main.js and current route
// 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 };
@@ -198,9 +197,7 @@ function get_route_handler(fn) {
const url = req.pathname;
// whatever happens, we're going to serve some HTML
res.set({
'Content-Type': 'text/html'
});
res.setHeader('Content-Type', 'text/html');
resolved
.then(() => {
@@ -212,7 +209,7 @@ function get_route_handler(fn) {
next();
})
.catch(err => {
res.status(500);
res.statusCode = 500;
res.end(templates.render(500, {
title: (err && err.name) || 'Internal server error',
url,
@@ -227,7 +224,7 @@ function get_not_found_handler(fn) {
return function handle_not_found(req, res) {
const asset_cache = fn();
res.status(404);
res.statusCode = 404;
res.end(templates.render(404, {
title: 'Not found',
status: 404,