angular-environment icon indicating copy to clipboard operation
angular-environment copied to clipboard

Defaults block is not actually the default

Open sirwesley opened this issue 7 years ago • 2 comments

According to the documentation, the 'defaults' block is supposed to be the catch-all area, however in testing it appears that 'development' is actually the catch-all section. Recommend fixing the code to make the 'defaults' block the catch-all area if there are no matches, or update the documentation to note that 'development' is the catch-all area if there are no matches.

sirwesley avatar Nov 15 '17 15:11 sirwesley

I believe development is the fallback if no other domains match. defaults will still provide vars not specified in the detected environment.

OzzieOrca avatar Jun 05 '20 17:06 OzzieOrca

You can change the fallback environment in the case where no domains match by calling set before check:

// set the domains and variables for each environment
envServiceProvider.config({
  domains: {
    development: ["localhost", "acme.dev.local"],
    production: ["acme.com", "*.acme.com", "acme.dev.prod"],
    test: ["test.acme.com", "acme.dev.test", "acme.*.com"],
    // anotherStage: ['domain1', 'domain2']
  },
  vars: {
    development: {
      apiUrl: "//api.acme.dev.local/v1",
      staticUrl: "//static.acme.dev.local",
      // antoherCustomVar: 'lorem',
      // antoherCustomVar: 'ipsum'
    },
    test: {
      apiUrl: "//api.acme.dev.test/v1",
      staticUrl: "//static.acme.dev.test",
      // antoherCustomVar: 'lorem',
      // antoherCustomVar: 'ipsum'
    },
    production: {
      apiUrl: "//api.acme.com/v1",
      staticUrl: "//static.acme.com",
      // antoherCustomVar: 'lorem',
      // antoherCustomVar: 'ipsum'
    },
    // anotherStage: {
    // 	customVar: 'lorem',
    // 	customVar: 'ipsum'
    // },
    defaults: {
      apiUrl: "//api.default.com/v1",
      staticUrl: "//static.default.com",
    },
  },
});

// default the environment to production
envServiceProvider.set('production')

// run the environment check, so the comprobation is made
// before controllers and services are built
envServiceProvider.check();

OzzieOrca avatar Jun 05 '20 18:06 OzzieOrca