From f4e46e6e6ccc16e44626262a8400c1a092f28e34 Mon Sep 17 00:00:00 2001 From: Luke Edwards Date: Fri, 19 Jan 2018 13:54:55 -0800 Subject: [PATCH] replace Express shorthands w/ native counterparts --- lib/index.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/index.js b/lib/index.js index 4d76472..8b3648a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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,