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); }); }); });