2
votes

I am making an Ember app using Ember-Cli which talks to a server side application. Because Ember-Cli projects run with their own server (on port 4200 by default), I have to run my server in development on a different port (localhost:8080) than the Ember app. In production, however, the two will be running on the same port.

Question: How can I configure Ember (in config/environment.js I presume) so that Ember-Data and all ajax requests will be made to localhost:8080 in development (in spite of the fact that the Ember app is running on 4200) and, in production, that Ember-Data and ajax requests will query whatever port the server side app is running on (which will be hosting the client side app).

Ember-Cli docs mention that some configuration can be done (for example that you can change the port that Ember-Cli runs on), however, it doesn't say how to accomplish the above

1

1 Answers

3
votes

You just want ember to use a different port for your API depending on the environment? It sounds like you need have your application adapter grab a value from your environment file

//environment.js
var ENV = {
  ...
  apiHost: 'https://path-to-production-api.com',
  ...
}

if (environment === 'development') {
   ENV.apiHost: 'http://localhost:8080'
}
ENV.contentSecurityPolicy['connect-src'] += ' ' + ENV.apiHost;

//adapters/application.js
import DS from 'ember-data';
import ENV from 'portal/config/environment';
export default DS.RESTAdapter.extend({
   host: ENV.apiHost
});