Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move config into meta. #2086

Merged
merged 1 commit into from
Sep 24, 2014
Merged

Move config into meta. #2086

merged 1 commit into from
Sep 24, 2014

Conversation

rwjblue
Copy link
Member

@rwjblue rwjblue commented Sep 23, 2014

  • Adds {{CONFIG_META}} to the app/index.html and tests/index.html.
  • Adds module at <my-app-name>/config/environment that simply reads the current meta value.
  • Removes <my-app-name>/config/environments/* from module system output.
  • Makes build output the same regardless of environment config.
  • Makes injection of custom config information as simple as adding/modifying/customizing the meta contents.

Closes #2059.

@stefanpenner
Copy link
Contributor

Nice

@lukemelia thoughts?

@rwjblue rwjblue force-pushed the meta-config branch 2 times, most recently from 2ba5f0e to ecd38b6 Compare September 23, 2014 20:53
rwjblue added a commit that referenced this pull request Sep 24, 2014
@rwjblue rwjblue merged commit e182108 into ember-cli:master Sep 24, 2014
@rwjblue rwjblue deleted the meta-config branch September 24, 2014 11:26
@lukemelia
Copy link
Contributor

😍 Very happy with where this ended up. Nice work!

@rwjblue
Copy link
Member Author

rwjblue commented Sep 25, 2014

@tchack - All you need to do is provide a define('your-app-name/config/environment', [], function() { }) and append it to the build to have the config embedded. It could be done as an option in the build though, but defaulting to the current <meta> solution.

@stefanpenner
Copy link
Contributor

@rwjblue we should probably document this, @tchak are you able to?

@rwjblue
Copy link
Member Author

rwjblue commented Sep 25, 2014

@stefanpenner - I'll make it an option. 'embedConfig' and default to false.

@stefanpenner
Copy link
Contributor

configAsModule:true|false ?

@rwjblue
Copy link
Member Author

rwjblue commented Sep 25, 2014

@stefanpenner - it is always a module (in both scenarios), the question is whether we add the module to load from meta or just contain static compiled info at build time.

@stefanpenner
Copy link
Contributor

ah true.

@tchak
Copy link
Contributor

tchak commented Sep 25, 2014

Awesome!

@joostdevries
Copy link
Member

@rwjblue are you working a PR for configAsModule:true or should I give it a go this weekend?

@rwjblue
Copy link
Member Author

rwjblue commented Oct 3, 2014

@joostdevries - I'm working on it, but would appreciate it if you could make an issue (and I can close that issue with my PR).

@ritesh83
Copy link

ritesh83 commented Oct 7, 2014

@rwjblue - We load our ember app inside an iframe and we are getting the following error:

Uncaught SyntaxError: Unexpected token u

Inside the following function:

define('client/config/environment', ['ember'], function(Ember) {
var metaName = 'client/config/environment';
var rawConfig = Ember['default'].$('meta[name="' + metaName + '"]').attr('content');
var config = JSON.parse(unescape(rawConfig));

return { 'default': config };
});

The 'rawConfig' is undefined.

It works fine if we don't load it inside an iframe.

Hope the option to disable it gets added in the next release.
Till then we'll use the 0.0.46 version.

Thanks for all your effort. Ember CLI is awesome!

@jurgenwerk
Copy link

I'm initialising Mixpanel and GA scripts in my index.html template and for that I need to fetch tokens from my ENV. Which I can't do from the controller property, because as far as I know the Ember is not yet initialised when rendering the index.html.

Currently I'm doing it like this (index.html):

<script>
  rawConfig = $('meta[name="my-client/config/environment"]').prop("content")
  window.ENV = JSON.parse(decodeURIComponent(rawConfig))
</script>

And, for example, using it later like this:

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', ENV.gaCode, 'auto');
</script>

Is there a better way to fetch ENV variables from config/environment.js in the index.html, to be used for inline JS scripts?

@joostdevries
Copy link
Member

@matixmatix I think you'll want to take a look at #2221 where some approaches for this are discussed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add EmberApp option to allow loading config in a separate file.
8 participants