Make Fastboot curlable withtout the Accept header

Hi,

I’m currently building an Heroku addon and the admin dashboard is using Ember. To check our compatibility with Heroku we’re using their kensa tool.

In order to test the SSO part, kensa is sending a POST request toa URL you provide. The endpoint it contacts is on our API that redirects to our dashboard in case of success.

To verify the success of the operation, kensa follows the redirection with a GET request, providing the following header: Accept: */*. In order to make all of this work, we used Fastboot but the problem is that Fastboot only answers if Accept: text/html is passed.

Is there any way to make Fastboot answer when Accept is a wildcard? I know it’s getting handled by Express, I saw it with DEBUG=express:* ember serve but I don’t know what to change to make it work.

Thanks!

How are you running fastboot? With Ember CLI? Fastboot-app-server? Or something else…?

If you’re running with Ember CLI (ember s) then you can add an express middleware that re-writes your accept headers to text/html for fastboot. We do something similar for Twitterbot testing.

// server/index.js

module.exports = function(app) {
  app.use('*', function(req, res, next) {
    req.headers['accept'] = 'text/html';
    next();
  });
};

This will re-write the accepts header for every request. If you’re proxying to an API server you be careful to not touch those headers.

It does seem reasonable to change the default behavior so it responds for wildcards that match text/html. So */* or text/*.

I’m still slightly confused by the question. Are we talking about the development server or a production scenario?

Hi @ryanto, it works! Thank you so much!

Currently I’m talking about the dev server but if @ryanto’s solution works for both I’m all-in. I’ve only check in development so far but I suppose it will work in prod :slightly_smiling_face:

It won’t work in prod since you most likely aren’t using Ember CLI to serve production pages. If you are, take a look at FastbootAppServer or the Fastboot express middleware, both of these are made for production. With these rewriting the accept header shouldn’t be required.

That said if you’re having trouble with prod post here, I’m sure it can be figured out :smiley:

This thread is a tad bit old, but google has brought me here multiple times today.

I’m experiencing the same, but the middleware is not picking up. It looks like something has changed in the format, but the generator still creates that scaffolding. Ember adds the following message:

The following options have been renamed — please update your config: exports → output.exports

What is the purpose of this selective header issue anyway?

I’ve added an issue in the hopes of clearing this up. fastboot only renders on `accept: text/html` header · Issue #676 · ember-fastboot/ember-cli-fastboot · GitHub