ember-cli-fastboot icon indicating copy to clipboard operation
ember-cli-fastboot copied to clipboard

fastboot only renders on `accept: text/html` header

Open Redsandro opened this issue 6 years ago • 0 comments

Using ember serve -prod we notice fastboot doesn't render unless the accept: text/html header is present.

However, many APIs use something else, e.g.: accept: */*. This means that fastboot is not activated, and model-dependent meta tags and OpenGraph data is not added.

Among other things, this impacts link sharing like on Slack.

Why is this? Can we change this through configuration? It seems a bit cumbersome if every single one of us would have to create some manual middleware to arteficially add the accept: text/html header.

Related:

  • https://discuss.emberjs.com/t/make-fastboot-curlable-withtout-the-accept-header/15038
  • https://discuss.emberjs.com/t/configuring-ember-clis-dev-server-to-respond-to-non-text-html-requests/14885

I've tried this:

npx ember generate in-repo-addon fastboot-accept

lib/fastboot-accept/index.js:

/**
 * Using `ember serve`, by defailt only `accept: text/html` will trigger fastboot.
 * This causes make OpenGraph parsers not to fastboot, because some will send `accept: *` or nothing at all.
 */
'use strict'

module.exports = {
	name: require('./package').name,

	serverMiddleware({app}) {
		app.use('*', (req, res, next) => {
			req.headers['accept'] = 'text/html'
			// console.log('%j', req.headers) // Verified

			next()
		})
	}
}

lib/fastboot-accept/package.json:

{
  "name": "fastboot-accept",
  "keywords": [
    "ember-addon"
  ],
  "ember-addon": {
    "before": "ember-cli-fastboot"
  }
}

Behavior does not change. It still does not activate fastboot when text/html header is not sent.

Redsandro avatar Mar 21 '19 21:03 Redsandro