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, diff --git a/test/common/test.js b/test/common/test.js index f044bda..250f596 100644 --- a/test/common/test.js +++ b/test/common/test.js @@ -41,7 +41,11 @@ function run(env) { }; const res = { - set: (headers, value) => { + setHeader(header, value) { + result.headers[header] = value; + }, + + set(headers, value) { if (typeof headers === 'string') { return res.set({ [headers]: value }); } @@ -49,15 +53,15 @@ function run(env) { Object.assign(result.headers, headers); }, - status: code => { + status(code) { result.status = code; }, - write: data => { + write(data) { result.body += data; }, - end: data => { + end(data) { result.body += data; fulfil(result); }