mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-12 11:15:14 +00:00
remove magic return values from server routes
This commit is contained in:
19
lib/index.js
19
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user