mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-21 23:05:02 +00:00
handle errors. (TODO: handle errors *nicely*)
This commit is contained in:
62
connect.js
62
connect.js
@@ -39,35 +39,36 @@ module.exports = function connect(opts) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const route of routes) {
|
try {
|
||||||
if (route.test(url)) {
|
for (const route of routes) {
|
||||||
req.params = route.exec(url);
|
if (route.test(url)) {
|
||||||
|
req.params = route.exec(url);
|
||||||
|
|
||||||
const chunk = await webpack_compiler.get_chunk(route.id);
|
const chunk = await webpack_compiler.get_chunk(route.id);
|
||||||
const mod = require(chunk);
|
const mod = require(chunk);
|
||||||
|
|
||||||
if (route.type === 'page') {
|
if (route.type === 'page') {
|
||||||
const main = await webpack_compiler.client_main;
|
const main = await webpack_compiler.client_main;
|
||||||
|
|
||||||
const page = opts.template({
|
const page = opts.template({
|
||||||
main,
|
main,
|
||||||
html: mod.default.render({
|
html: mod.default.render({
|
||||||
params: req.params,
|
params: req.params,
|
||||||
query: req.query
|
query: req.query
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
res.status(200);
|
res.status(200);
|
||||||
res.set({
|
res.set({
|
||||||
// TODO etag stuff
|
// TODO etag stuff
|
||||||
'Content-Length': page.length,
|
'Content-Length': page.length,
|
||||||
'Content-Type': 'text/html'
|
'Content-Type': 'text/html'
|
||||||
});
|
});
|
||||||
res.end(page);
|
res.end(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
const handler = mod[req.method.toLowerCase()];
|
const handler = mod[req.method.toLowerCase()];
|
||||||
if (handler) {
|
if (handler) {
|
||||||
if (handler.length === 2) {
|
if (handler.length === 2) {
|
||||||
handler(req, res);
|
handler(req, res);
|
||||||
@@ -82,12 +83,17 @@ module.exports = function connect(opts) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
next();
|
next();
|
||||||
|
} catch(err) {
|
||||||
|
// TODO nice error pages
|
||||||
|
res.status(500);
|
||||||
|
res.end(err.message);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user