mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-20 14:25:07 +00:00
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:
@@ -136,6 +136,9 @@ function get_route_handler(fn) {
|
|||||||
const mod = require(server.entry)[route.id];
|
const mod = require(server.entry)[route.id];
|
||||||
|
|
||||||
if (route.type === 'page') {
|
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
|
// 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.setHeader('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"`);
|
||||||
@@ -196,9 +199,6 @@ function get_route_handler(fn) {
|
|||||||
return function find_route(req, res, next) {
|
return function find_route(req, res, next) {
|
||||||
const url = req.pathname;
|
const url = req.pathname;
|
||||||
|
|
||||||
// whatever happens, we're going to serve some HTML
|
|
||||||
res.setHeader('Content-Type', 'text/html');
|
|
||||||
|
|
||||||
resolved
|
resolved
|
||||||
.then(() => {
|
.then(() => {
|
||||||
for (const route of route_manager.routes) {
|
for (const route of route_manager.routes) {
|
||||||
@@ -265,4 +265,4 @@ function try_serialize(data) {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user