remove magic return values from server routes

This commit is contained in:
Rich Harris
2017-12-17 15:01:05 -05:00
parent 34d0bae4a1
commit 62abdb2a87

View File

@@ -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 // whatever happens, we're going to serve some HTML
res.set({ res.set({
'Content-Type': 'text/html' 'Content-Type': 'text/html'
@@ -128,20 +128,7 @@ module.exports = function connect(opts) {
else { else {
const handler = mod[req.method.toLowerCase()]; const handler = mod[req.method.toLowerCase()];
if (handler) { if (handler) handler(req, res, next);
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));
}
}
}
} }
return; return;
@@ -170,7 +157,7 @@ module.exports = function connect(opts) {
handle_index(url, req, res, () => { handle_index(url, req, res, () => {
handle_service_worker(url, req, res, () => { handle_service_worker(url, req, res, () => {
handle_webpack_generated_files(url, req, res, () => { handle_webpack_generated_files(url, req, res, () => {
handle_route(url, req, res); handle_route(url, req, res, next);
}); });
}); });
}); });