Access {{ENV} }enviroment in index.html

At Index.html I would like to use window.appEnv = {{ENV}}

with config/environment.js, ENV have been defined already.

I built and served the ember and got Uncaught SyntaxError: Unexpected token {

What wrong with my index.html

Using {{varname}} is HTMLBars syntax but index.html isn’t an HTMLBars (.hbs) file so you can only use normal HTML inside. Can you describe what you’re trying to accomplish with appEnv and maybe we can recommend something? You can import your environment config in any of your app javascript as shown here in the guides.

Circling back to this / and example: we have a block of open-graph on a quick - short-lived game type Ember app. The share asset needs a full absolute path for the protocol - and it’s going up to 3 different servers / with different URLs. We know that the index file doesn’t have handlebars / but it does have some dynamic stuff happening - like {{rootURL}} - so, what’s the story?

1 Like

We use process.env.DEPLOY_TARGET and also added ENV.domainURL for the cases where we can’t go without this info. It is not direct clear from the documentation but each deployed site uses the environment production. So in our case staging and production both use the production environment.

app/config/environment.js

'use strict';

module.exports = function(environment) {
  let deployTarget = process.env.DEPLOY_TARGET;
  let ENV = {
    domainURL: 'https://www.martinic.com', //Without ending slash
    .......  
   },
    
  if (environment === 'development') {
    ENV.domainURL = 'http://localhost:4200'; //Without ending slash
  }
  
  if (environment === 'production') {
    // here you can enable a production-specific feature
  }

  if (deployTarget === 'staging') {
    ENV.domainURL = 'https://staging.martinic.com'; //Without ending slash
  }

  return ENV;
};

app/config/deploy.js

module.exports = function(deployTarget) {
  var ENV = { };

  if (deployTarget === 'production') {
    ENV.sftp = {
      host: 'ip.martinic.com',
      port: 2222,
      remoteDir: '/home/martinic/martinic.com/www/',
      remoteUser: process.env.remoteUser,
      privateKey: process.env.privateKey
    };
  }
  if (deployTarget === 'staging') {
    ENV.sftp = {
      host: 'ip.martinic.com',
      port: 2222,
      remoteDir: '/home/martinic/staging.martinic.com/www/',
      remoteUser: process.env.remoteUser,
      privateKey: process.env.privateKey
    };
  }

  return ENV;
};

You can deploy to as much servers and urls you need to deploy to.

1 Like

I think If u have {{content-for ‘head’}} in index.html there is an meta tag with name=app/config/environment and its content as urlencoded json of environment parameters.you can access with plain js on your index.html using script tag.

Another way to solve some of the problems people are describing in this thread is ember-cli-head.