Configuring Ember CLI's dev server to respond to non-`text/html` requests

We’re developing our Ember app locally and tweaking how it responds to Slack.

When we make a request from Slack to our app, Ember CLI doesn’t render a response – it returns a 404 instead. We tracked this down to the fact that Slack doesn’t include an Accept: text/html header in its request. (If we curl our app without the header, we see the same thing, but if we add that one header, it responds correctly).

We think it’s due to this line in the history-support middleware:

https://github.com/ember-cli/ember-cli/blob/master/lib/tasks/server/middleware/history-support/index.js#L66

Is there a simple way to reconfigure this so that Ember CLI’s dev server can respond to requests that don’t have this header?

We ended up using an express middleware to re-write these requests to have an Accepts: text/html

// server/index.js

module.exports = function(app) {
  const globSync = require('glob').sync;
  const proxies = globSync('./proxies/**/*.js', { cwd: __dirname }).map(require);

  const morgan = require('morgan');
  app.use(morgan('dev'));

  app.use(function(req, res, next) {
   // most bots/curl will only send accept "*/*", rewrite to "text/html" so these requests are
   // served by ember-cli
    if (req.headers['accept'] === "*/*") {
      req.headers['accept'] = 'text/html';
    }

    next();
  });

  proxies.forEach(route => route(app));
};

I’m curious about where did you put this middleware? :thinking:

Also, you guys are using FastBoot, aren’t you?

Ah good catch! This code is located in the server/index.js file.

And yup, we’re using fastboot.

1 Like