Created
February 11, 2018 14:31
-
-
Save nsmgr8/c4411391918c773447497af01533dd78 to your computer and use it in GitHub Desktop.
This file contains 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
process.env.ts |
This file contains 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
import { process_env } from './process.env'; | |
const api_url = process_env['API_URL'] || location.hostname; | |
const api_key = process_env['API_KEY'] || 'LOCAL-DEFAULT-KEY'; | |
export const environment = { | |
production: false, | |
api_url, | |
api_key | |
}; |
This file contains 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
{ | |
... | |
"scripts": { | |
... | |
"prestart": "node prestart.js", | |
"start": "ng serve", | |
... | |
}, | |
... | |
} |
This file contains 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
#!/usr/bin/env node | |
const fs = require('fs'); | |
const path = require('path'); | |
const vars = require('./process.env').vars; | |
const env_vars = {}; | |
vars.forEach(x => { | |
if (vars.indexOf(x) !== -1) { | |
env_vars[x] = process.env[x]; | |
} | |
}); | |
const env_path = path.join(__dirname, 'src', 'environments', 'process.env.ts'); | |
const env_str = JSON.stringify(env_vars, null, ' '); | |
fs.writeFileSync(env_path, `export const process_env = ${env_str};`); | |
process.exit(0); |
This file contains 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
exports.vars = [ | |
'API_URL', | |
'API_KEY' | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment