fastboot-express-middleware
fastboot-express-middleware copied to clipboard
Add Content-Type: text/html; charset-utf8
This is lightly tested on my local machine. I think we need to add this because the initial FastBoot request is missing a content-type header. See my issue here: https://github.com/ember-fastboot/fastboot-app-server/issues/78
This is important because some Node-based crawlers simply break without a content-type header. Also Twitterbot doesn't seem to be able to get meta tags when this header is not present.
I had a user report to me that Safari just downloads the HTML file immediately and I believe this is because my site has the X-Content-Type-Options header set to nosniff. 😞
I've realized this is only needed in the chunkedResponse case. I've updated the PR.
Note: I still had to add this in fastboot-app-server to get things working in production 🤷♂️ :
// HACK: When using `chunkedResponse` we have to explicitly set the content
// type otherwise the header is missing.
app.use(function(req, res, next) {
if (!req.url.includes('.')) {
res.type('html');
}
next();
});