Environment-based host in Ember CLI app

后端 未结 2 1100
一整个雨季
一整个雨季 2021-02-19 22:35

I\'m trying to configure the adapter in my Ember CLI app to use a different host based on the environment. In dev, I want it to be the default current host (letting me customize

2条回答
  •  抹茶落季
    2021-02-19 22:56

    You are pretty close. You should only going up one step in the directory tree (when you are in a route, controller, etc you need to go up two).

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

    The documentation is here.

    Note you probably shouldn't be defining your own variables directly on ENV. Use ENV.APP in config/environment.js

    var ENV = {
      ...
      APP: {
        // Here you can pass flags/options to your application instance
        // when it is created
        host: 'some_host'
      }
    };
    

    And access it the same way

    import ENV from '../config/environment';
    
    export default DS.ActiveModelAdapter.extend({
      host: ENV.APP.host
    });
    

提交回复
热议问题