ember-fastboot / ember-fastboot/ember-cli-fastboot

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

Open
#676 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
850
Forks
161
Avg merge
17h 45m
Merged PRs (30d)
19

Description

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`:
```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`:
```js
{
"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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.