ember-fastboot / fastboot-app-server

A production-ready app server for running Ember FastBoot apps
140 stars 72 forks source link

Missing Content-Type header #78

Open mhluska opened 6 years ago

mhluska commented 6 years ago

The initial response for the html page is missing Content-Type: text/html; charset=utf-8.

I think the reason this is happening is express-http-server.js has the following code:

 52     if (this.distPath) {
 53       app.get('/', fastbootMiddleware);
 54       app.use(express.static(this.distPath));
 55       app.get('/assets/*', function(req, res) {
 56         res.sendStatus(404);
 57       });
 58     }

app.get('/', fastbootMiddleware); causes the initial request to not have the correct content-type since that is normally handled by express.static.

So it seems fastboot-express-middleware needs to call .type('text/html') somewhere.

st-h commented 5 years ago

I just have been running into exactly this issue and noticed that it only shows up when using chunkedResponse: true. Looks like using chunkedResponse: false seems to work as a workaround. Unfortunately the readme has chunkedResponse: true within its example, so most people starting to integrate FastBoot will likely hit this issue at some point.

mcfiredrill commented 5 years ago

I was having trouble getting some twitter cards to work, and noticed this message at the bottom: https://github.com/ember-fastboot/fastboot-app-server#scraper-issues

As of 2019-06-06, Twitter and LinkedIn's scrapers have a hard time extracting your site's metadata for sharing if chunkedResponse is set to true in your server.js file. Set chunkedResponse: false if your meta tags are in place but the Twitter card validator shows "Card not found" or LinkedIn's Post Inspector shows a 500 error.

But I actually posted in the twitter dev forum before seeing this, and got a response that it was because I'm missing a content-type header. https://twittercommunity.com/t/warn-no-metatags-found-even-though-they-are-there/127287

So maybe the issue is not the chunkedResponse but the missing content-type header? 🤔

mariusleu commented 10 months ago

For everyone having scraping issues with ember-fastboot apps, such as LinkedIn, Twitter, etc, setting chunkedResponse: false solves the issue. It adds back the Content-Type: text/html which is missing.