mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-20 14:25:07 +00:00
Merge branch 'master' of github.com:sveltejs/sapper
This commit is contained in:
17
lib/index.js
17
lib/index.js
@@ -120,10 +120,9 @@ function get_asset_handler(opts) {
|
|||||||
return (req, res, next) => {
|
return (req, res, next) => {
|
||||||
if (!opts.filter(req.pathname)) return next();
|
if (!opts.filter(req.pathname)) return next();
|
||||||
|
|
||||||
res.set({
|
res.setHeader('Content-Type', opts.type);
|
||||||
'Content-Type': opts.type,
|
res.setHeader('Cache-Control', opts.cache);
|
||||||
'Cache-Control': opts.cache
|
|
||||||
});
|
|
||||||
res.end(opts.fn(req.pathname));
|
res.end(opts.fn(req.pathname));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -139,7 +138,7 @@ function get_route_handler(fn) {
|
|||||||
if (route.type === 'page') {
|
if (route.type === 'page') {
|
||||||
// preload main.js and current route
|
// preload main.js and current route
|
||||||
// TODO detect other stuff we can preload? images, CSS, fonts?
|
// TODO detect other stuff we can preload? images, CSS, fonts?
|
||||||
res.set('Link', `<${client.main_file}>;rel="preload";as="script", <${client.routes[route.id]}>;rel="preload";as="script"`);
|
res.setHeader('Link', `<${client.main_file}>;rel="preload";as="script", <${client.routes[route.id]}>;rel="preload";as="script"`);
|
||||||
|
|
||||||
const data = { params: req.params, query: req.query };
|
const data = { params: req.params, query: req.query };
|
||||||
|
|
||||||
@@ -198,9 +197,7 @@ function get_route_handler(fn) {
|
|||||||
const url = req.pathname;
|
const url = req.pathname;
|
||||||
|
|
||||||
// whatever happens, we're going to serve some HTML
|
// whatever happens, we're going to serve some HTML
|
||||||
res.set({
|
res.setHeader('Content-Type', 'text/html');
|
||||||
'Content-Type': 'text/html'
|
|
||||||
});
|
|
||||||
|
|
||||||
resolved
|
resolved
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@@ -212,7 +209,7 @@ function get_route_handler(fn) {
|
|||||||
next();
|
next();
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
res.status(500);
|
res.statusCode = 500;
|
||||||
res.end(templates.render(500, {
|
res.end(templates.render(500, {
|
||||||
title: (err && err.name) || 'Internal server error',
|
title: (err && err.name) || 'Internal server error',
|
||||||
url,
|
url,
|
||||||
@@ -227,7 +224,7 @@ function get_not_found_handler(fn) {
|
|||||||
return function handle_not_found(req, res) {
|
return function handle_not_found(req, res) {
|
||||||
const asset_cache = fn();
|
const asset_cache = fn();
|
||||||
|
|
||||||
res.status(404);
|
res.statusCode = 404;
|
||||||
res.end(templates.render(404, {
|
res.end(templates.render(404, {
|
||||||
title: 'Not found',
|
title: 'Not found',
|
||||||
status: 404,
|
status: 404,
|
||||||
|
|||||||
@@ -41,7 +41,11 @@ function run(env) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const res = {
|
const res = {
|
||||||
set: (headers, value) => {
|
setHeader(header, value) {
|
||||||
|
result.headers[header] = value;
|
||||||
|
},
|
||||||
|
|
||||||
|
set(headers, value) {
|
||||||
if (typeof headers === 'string') {
|
if (typeof headers === 'string') {
|
||||||
return res.set({ [headers]: value });
|
return res.set({ [headers]: value });
|
||||||
}
|
}
|
||||||
@@ -49,15 +53,15 @@ function run(env) {
|
|||||||
Object.assign(result.headers, headers);
|
Object.assign(result.headers, headers);
|
||||||
},
|
},
|
||||||
|
|
||||||
status: code => {
|
status(code) {
|
||||||
result.status = code;
|
result.status = code;
|
||||||
},
|
},
|
||||||
|
|
||||||
write: data => {
|
write(data) {
|
||||||
result.body += data;
|
result.body += data;
|
||||||
},
|
},
|
||||||
|
|
||||||
end: data => {
|
end(data) {
|
||||||
result.body += data;
|
result.body += data;
|
||||||
fulfil(result);
|
fulfil(result);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user