From 71cfdd290715d9e3f62bd02106d02466f593440d Mon Sep 17 00:00:00 2001 From: Sam Hatchett Date: Wed, 31 Jan 2018 11:08:25 -0500 Subject: [PATCH] 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. --- lib/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/index.js b/lib/index.js index 8b3648a..ecd4198 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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; } -} \ No newline at end of file +}