From 62abdb2a87ad6b3c3616ebcfc4a07f95864b7753 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 17 Dec 2017 15:01:05 -0500 Subject: [PATCH] remove magic return values from server routes --- lib/index.js | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/lib/index.js b/lib/index.js index 10ce4c3..573367f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -94,7 +94,7 @@ module.exports = function connect(opts) { } } - async function handle_route(url, req, res) { + async function handle_route(url, req, res, next) { // whatever happens, we're going to serve some HTML res.set({ 'Content-Type': 'text/html' @@ -128,20 +128,7 @@ module.exports = function connect(opts) { else { const handler = mod[req.method.toLowerCase()]; - if (handler) { - if (handler.length === 2) { - handler(req, res); - } else { - const data = await handler(req); - - // TODO headers, error handling - if (typeof data === 'string') { - res.end(data); - } else { - res.end(JSON.stringify(data)); - } - } - } + if (handler) handler(req, res, next); } return; @@ -170,7 +157,7 @@ module.exports = function connect(opts) { handle_index(url, req, res, () => { handle_service_worker(url, req, res, () => { handle_webpack_generated_files(url, req, res, () => { - handle_route(url, req, res); + handle_route(url, req, res, next); }); }); });