Created
February 26, 2015 18:22
-
-
Save ultimatemonty/7bf61a23106a275bad14 to your computer and use it in GitHub Desktop.
Environment Config vars in an Ember globals app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.SimpleAuthCredentialsAuthenticator = SimpleAuth.Authenticators.Base.extend({ | |
setup: function () { | |
console.log(this.get('config')); // undefined | |
this.set('serverTokenEndpoint', this.get('config.api_servertokenendpoint')) // throws EX and poops out | |
}.on('init') | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ember.Application.initializer({ | |
name: 'config', | |
after: 'ember-simple-auth-initializer', | |
initialize: function(container, application) { | |
var envTag = $('meta[name="env-name"]'); | |
var environment; | |
if (!envTag) { | |
throw new Ember.Error("No config environment present in index.html."); | |
} | |
environment = $(envTag).attr('value'); | |
var app_environment = environment, | |
api_serverTokenEndpoint, | |
api_host, | |
api_namespace, | |
pubnub_subscribeKey, | |
pubnub_publishKey, | |
pubnub_uuid, | |
pubnub_enable_ssl; | |
if (environment === 'development') { | |
// API | |
api_servertokenendpoint = 'http://localhost:64499/auth/credentials'; | |
api_host = 'http://localhost:64499'; | |
api_namespace = ''; | |
// more config stuff (3rd party API Keys, etc...) | |
// ... | |
// ... | |
} | |
if (environment === 'test') { | |
// API | |
api_servertokenendpoint = 'http://my.test.server/auth/credentials'; | |
api_host = 'http://my.test.server'; | |
api_namespace = 'api_test'; | |
// more config stuff (3rd party API Keys, etc...) | |
// ... | |
// ... | |
} | |
if (environment === 'production') { | |
// API | |
api_servertokenendpoint = 'https://my.prod.server/auth/credentials'; | |
api_host = 'https://my.prod.server'; | |
api_namespace = 'api'; | |
// more config stuff (3rd party API Keys, etc...) | |
// ... | |
// ... | |
} | |
if (Ember.empty(api_host)) { | |
throw new Ember.Error("No config found for environment `" + environment + "`. ENV-NAME should be `development`, `test`, or `production`."); | |
} | |
var config = Ember.Object.extend({ | |
// environment | |
app_environment: app_environment, | |
// api endpoints | |
api_servertokenendpoint: api_serverTokenEndpoint, | |
api_host: api_host, | |
api_namespace: api_namespace | |
}); | |
application.register('config:main', config, { singleton: true, instantiate: true }); // works | |
application.inject('controller', 'config', 'config:main'); // works | |
application.inject('adapter', 'config', 'config:main'); // works | |
application.inject('service', 'config', 'config:main'); // works | |
application.inject('authenticator', 'config', 'config:main'); // BIG GIANT WTF IT DOESN'T WORK | |
application.inject('authorizer', 'config', 'config:main'); // BIG GIANT WTF IT DOESN'T WORK | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment