mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-21 06:45:00 +00:00
server-side preloading, and critical CSS rendering
This commit is contained in:
14
connect.js
14
connect.js
@@ -50,18 +50,20 @@ module.exports = function connect(opts) {
|
|||||||
if (route.type === 'page') {
|
if (route.type === 'page') {
|
||||||
const main = await webpack_compiler.client_main;
|
const main = await webpack_compiler.client_main;
|
||||||
|
|
||||||
|
let data = { params: req.params, query: req.query };
|
||||||
|
if (mod.default.preload) data = Object.assign(data, await mod.default.preload(data));
|
||||||
|
|
||||||
|
const { html, css } = mod.default.render(data);
|
||||||
|
|
||||||
const page = opts.template({
|
const page = opts.template({
|
||||||
main,
|
main,
|
||||||
html: mod.default.render({
|
html,
|
||||||
params: req.params,
|
css: (css && css.code || '')
|
||||||
query: req.query
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
res.status(200);
|
res.status(200);
|
||||||
res.set({
|
res.set({
|
||||||
// TODO etag stuff
|
// TODO etag stuff
|
||||||
'Content-Length': page.length,
|
|
||||||
'Content-Type': 'text/html'
|
'Content-Type': 'text/html'
|
||||||
});
|
});
|
||||||
res.end(page);
|
res.end(page);
|
||||||
@@ -93,7 +95,7 @@ module.exports = function connect(opts) {
|
|||||||
} catch(err) {
|
} catch(err) {
|
||||||
// TODO nice error pages
|
// TODO nice error pages
|
||||||
res.status(500);
|
res.status(500);
|
||||||
res.end(err.message);
|
res.end(err.stack);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user