Make Fastboot curlable withtout the Accept header


#1

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!


#2

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


#3

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.


#4

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


#5

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


#6

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


#7

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:


#8

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: