Skip to content

Instantly share code, notes, and snippets.

@nsmgr8
Created February 11, 2018 14:31
Show Gist options
  • Save nsmgr8/c4411391918c773447497af01533dd78 to your computer and use it in GitHub Desktop.
Save nsmgr8/c4411391918c773447497af01533dd78 to your computer and use it in GitHub Desktop.
process.env.ts
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
};
{
...
"scripts": {
...
"prestart": "node prestart.js",
"start": "ng serve",
...
},
...
}
#!/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);
exports.vars = [
'API_URL',
'API_KEY'
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment