fixes api route default content-type

fixes issue where api routes were being defaulted to text/html. Page routes should be text/html, but api routes could be json, zip files, etc., and express does some type-guessing to assist in case the user code does not specify the content-type.
This commit is contained in:
Sam Hatchett
2018-01-31 11:08:25 -05:00
committed by GitHub
parent 7a3506420f
commit 71cfdd2907

View File

@@ -136,6 +136,9 @@ function get_route_handler(fn) {
const mod = require(server.entry)[route.id];
if (route.type === 'page') {
// for page routes, we're going to serve some HTML
res.setHeader('Content-Type', 'text/html');
// preload main.js and current route
// TODO detect other stuff we can preload? images, CSS, fonts?
res.setHeader('Link', `<${client.main_file}>;rel="preload";as="script", <${client.routes[route.id]}>;rel="preload";as="script"`);
@@ -196,9 +199,6 @@ function get_route_handler(fn) {
return function find_route(req, res, next) {
const url = req.pathname;
// whatever happens, we're going to serve some HTML
res.setHeader('Content-Type', 'text/html');
resolved
.then(() => {
for (const route of route_manager.routes) {
@@ -265,4 +265,4 @@ function try_serialize(data) {
} catch (err) {
return null;
}
}
}