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

Remove window.MyAppNameENV. #1903

Merged
merged 1 commit into from
Sep 6, 2014
Merged

Conversation

rwjblue
Copy link
Member

@rwjblue rwjblue commented Sep 6, 2014

Closes #1895.

I decided to not go with a deprecation for now. Having to manually update your app (and a 0.0.x number) means it is likely OK to have a bit of upgrading to do.

@jayphelps
Copy link
Member

*You're SOL

@fivetanley
Copy link
Contributor

How should I access the information here if it's not available globally? I'm using it for a few things like API_HOST and whatnot.

@rwjblue
Copy link
Member Author

rwjblue commented Sep 6, 2014

import config from '../config/environment';

@jayphelps
Copy link
Member

@fivetanley

import ENV from '<appName>/config/environment';
ENV.API_HOST; // example.com

@fivetanley
Copy link
Contributor

mind blown

@rwjblue
Copy link
Member Author

rwjblue commented Sep 6, 2014

I want to hold off on this until after 0.0.44 is out.

@rwjblue rwjblue added this to the 0.0.45 milestone Sep 6, 2014
@brandonparsons
Copy link

@jayphelps @rwjblue What if you are not in an environment where you can import ENV from '<appName>/config/environment'; ?

i.e. After

    <script>
      window.MyAppENV = {{ENV}};
    </script>

I had been using window.MyAppENV.SOME_CONFIG_VAR to keep environment-specific data for use in index.html (for various external libraries). Am I doing something wrong?

@joostdevries
Copy link
Member

@brandonparsons I'm doing the following which works quite well for me:

    <script>
      (function(){
        var config = require('app/config/environment')['default'];
        config.foo = 'bar';
        window.EmberENV = config.EmberENV;
        require('app/app')['default'].create(config.APP);
      })();
    </script>

rwjblue added a commit that referenced this pull request Sep 6, 2014
@rwjblue rwjblue merged commit 91716ee into ember-cli:master Sep 6, 2014
@rwjblue rwjblue deleted the remove-env-global branch September 6, 2014 20:21
@stefanpenner
Copy link
Contributor

Yay

@stefanpenner
Copy link
Contributor

One more step to strict csp compliance

@alvincrespo
Copy link

@joostdevries Thanks for sharing that - saved my day :)

@suni123
Copy link

suni123 commented Oct 7, 2014

Can anyone please help regarding ember-cli.
I need to store a variable with url (some other service url)as value and it should be available across the application,how it can be acheived

@ahacking
Copy link

ahacking commented Oct 7, 2014

You can set the variable in config/environment.js under the APP key, eg:

  var ENV = {
    ...
    APP = {
     apiURL: "http://example.com"
    }
  };
  ...

Then where you need access just import the config module and use the variable. For example:

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

export default DS.RESTAdapter.extend({
  host: config.APP.apiURL,
  ...
});

@suni123
Copy link

suni123 commented Oct 7, 2014

Hi,

I tried to import the config file(import config from '../config/environment';), I want to do this in controller file,I am getting the following error while building

ENOENT, no such file or directory 'D:\CPS\CPS-UI\cpsui\tmp\tree_merger-tmp_dest_dir-GDbdsFCI.tmp\todo-ember\config\environment.js'
File: todo-ember/config/environment.js
Error: ENOENT, no such file or directory 'D:\CPS\CPS-UI\cpsui\tmp\tree_merger-tmp_dest_dir-GDbdsFCI.tmp\todo-ember\config\environment.js'
at Object.fs.statSync (fs.js:689:18)
at addModule (D:\CPS\CPS-UI\cpsui\node_modules\ember-cli\node_modules\broccoli-es6-concatenator\index.js:83:46)
at addModule (D:\CPS\CPS-UI\cpsui\node_modules\ember-cli\node_modules\broccoli-es6-concatenator\index.js:126:9)
at D:\CPS\CPS-UI\cpsui\node_modules\ember-cli\node_modules\broccoli-es6-concatenator\index.js:59:7
at $$$internal$$tryCatch (D:\CPS\CPS-UI\cpsui\node_modules\ember-cli\node_modules\rsvp\dist\rsvp.js:464:16)
at $$$internal$$invokeCallback (D:\CPS\CPS-UI\cpsui\node_modules\ember-cli\node_modules\rsvp\dist\rsvp.js:476:17)
at $$$internal$$publish (D:\CPS\CPS-UI\cpsui\node_modules\ember-cli\node_modules\rsvp\dist\rsvp.js:447:11)
at $$rsvp$asap$$flush (D:\CPS\CPS-UI\cpsui\node_modules\ember-cli\node_modules\rsvp\dist\rsvp.js:1525:9)
at process._tickCallback (node.js:419:13)

Please help,many thanks for quick response

@suni123
Copy link

suni123 commented Oct 7, 2014

Hi ,

Is there any other way to import config file.

Please help

@stefanpenner
Copy link
Contributor

import config from '<app-name>'/config/environment';

@suni123
Copy link

suni123 commented Oct 7, 2014

I tried everything ,but everytime I build it is giving me tmp folder error no such file exist

@rwjblue
Copy link
Member Author

rwjblue commented Oct 7, 2014

Most likely you are not running a version of ember-cli that supports this. Please upgrade to the latest version.

@suni123
Copy link

suni123 commented Oct 7, 2014

npm ver -1.4.21
ember ver -0.0.40
node ver - 0.10.29

the config folder is outside the app folder ,so will the import work

@suni123
Copy link

suni123 commented Oct 8, 2014

Hi,

I was able to access the environment data in controller by accessing it through index.html
e.g var serURL = window.appnameENV.APP.accessurl

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.

remove <AppName>Env global entirely
10 participants