0
votes

I'm using Ember-cli-mirage to mock data. I want to slowly integrate parts of the production api which is located on my local machine at http://localhost:8000. Ember docs tell me that I should be able to set an adapter so I can have a different host for each model.

I have a customer model, and have setup ember-cli-mirage which is successfully serving data. The customer model is the first model I want to split out to localhost:8000.

I've setup adapters/customer.js with the following:

import DS from 'ember-data';

export default DS.RESTAdapter.extend( {
  host: 'http://localhost:8000',
  namespace: 'api/v1'
});

But when I make the call I'm getting an error:

Mirage: Error: Your Ember app tried to GET 'http://localhost:8000/api/v1/customers',
         but there was no route defined to handle this request.
         Define a route that matches this path in your
         mirage/config.js file. Did you forget to add your namespace?

And my header inspector shows that customers is making the request to the mirage server:

Request URL:http://localhost:6543/customers
Request Method:GET
Status Code:304 Not Modified
Remote Address:[::1]:6543

I suspect it's something to do with my config/environment.js setup so I'm looking at a variation of https://github.com/samselikoff/ember-cli-mirage/issues/497#issuecomment-183458721 as a potential workaround. But I can't see why mirage won't accept the adapter overide.

1

1 Answers

0
votes

Should have read back through the mirage docs for this one. There's a passthrough function that allows mirage to pass certain requests through to Ember bypassing mirage:

// mirage/config.js
import Mirage from 'ember-cli-mirage';

export default function() {

  this.urlPrefix = 'http://localhost:8000';
  this.namespace = '/api/v1';

  // Requests for customers
  this.get('/customers');
  this.get('/customers/:id');
  this.post('/customers');
  this.del('/customers/:id');
  this.patch('/customers/:id');

  // Passthrough to Django API
  this.passthrough('/customers');

}

To make this work in my application adapter I added:

// app/adapters/application.js
import DS from 'ember-data';

export default DS.RESTAdapter.extend({
  host: 'http://localhost:8000',
  namespace: 'api/v1'
});

If this helps you in any way feel free to give this answer an upvote :)