Ensure correct environment file used.

This commit is contained in:
William Welling
2017-03-27 08:31:12 -05:00
parent 648383405a
commit 9c46ec1564
6 changed files with 37 additions and 33 deletions

View File

@@ -1,18 +1,19 @@
module.exports = {
// The REST API server settings.
"rest": {
// NOTE: Space is capitalized because 'namespace' is a reserved string in TypeScript
"nameSpace": "/api",
"protocol": "http",
"ssl": false,
"address": "localhost",
"port": 3000
"port": 3000,
// NOTE: Space is capitalized because 'namespace' is a reserved string in TypeScript
"nameSpace": "/api"
},
// Angular2 UI server settings.
"ui": {
"nameSpace": "/",
"protocol": "http",
"ssl": false,
"address": "localhost",
"port": 3000
"port": 3000,
// NOTE: Space is capitalized because 'namespace' is a reserved string in TypeScript
"nameSpace": "/"
},
"cache": {
// how long should objects be cached for by default

View File

@@ -10,8 +10,12 @@ import { bootloader } from '@angularclass/bootloader';
import { load as loadWebFont } from 'webfontloader';
import { EnvConfig } from './config';
if (EnvConfig.production) {
// enable prod for faster renders
// enableProdMode();
enableProdMode();
}
import { MainModule } from './platform/modules/browser.module';

View File

@@ -2,10 +2,10 @@
import { OpaqueToken } from '@angular/core';
interface ServerConfig {
"nameSpace": string;
"protocol": string;
"ssl": boolean;
"address": string;
"port": number;
"nameSpace": string;
"baseUrl": string;
}
@@ -32,27 +32,28 @@ let EnvConfigFile: string;
let production: boolean = false;
// check process.env.NODE_ENV to determine which environment config to use
// process.env.NODE_ENV is defined by webpack, else assume development
switch (process.env.NODE_ENV) {
case 'prod':
case 'production':
production = true;
// webpack.prod.config.ts defines process.env.NODE_ENV = 'production'
EnvConfigFile = './environment.prod.js';
break;
case 'dev':
case 'development':
EnvConfigFile = './environment.dev.js';
production = true;
break;
case 'test':
// webpack.test.config.ts defines process.env.NODE_ENV = 'test'
EnvConfigFile = './environment.test.js';
break;
default:
console.warn('Environment file not specified. Using default.');
// if not using webpack.prod.config.ts or webpack.test.config.ts, it must be development
EnvConfigFile = './environment.dev.js';
}
try {
EnvConfig = configContext('./environment.default.js');
} catch (e) {
throw new Error("Cannot find file ./environment.default.js");
throw new Error("Cannot find file environment.default.js");
}
// if EnvConfigFile set try to get configs
@@ -60,18 +61,18 @@ if (EnvConfigFile) {
try {
EnvConfig = <GlobalConfig>Object.assign(EnvConfig, configContext(EnvConfigFile));
} catch (e) {
console.warn("Cannot find file " + EnvConfigFile);
console.warn("Cannot find file " + EnvConfigFile.substring(2, EnvConfigFile.length), "Using default environment.");
}
}
// set base url if propery is object with protocol, address, and port. i.e. ServerConfig
// set base url if property is object with ssl, address, and port. i.e. ServerConfig
for (let key in EnvConfig) {
if (EnvConfig[key].protocol && EnvConfig[key].address && EnvConfig[key].port) {
EnvConfig[key].baseUrl = [EnvConfig[key].protocol, '://', EnvConfig[key].address, (EnvConfig[key].port !== 80) ? ':' + EnvConfig[key].port : ''].join('');
if (EnvConfig[key].ssl !== undefined && EnvConfig[key].address && EnvConfig[key].port) {
EnvConfig[key].baseUrl = [EnvConfig[key].ssl ? 'https://' : 'http://', EnvConfig[key].address, (EnvConfig[key].port !== 80) ? ':' + EnvConfig[key].port : ''].join('');
}
}
// set config for running in production
// set config for whether running in production
EnvConfig.production = production;
export { GLOBAL_CONFIG, GlobalConfig, EnvConfig }

View File

@@ -124,5 +124,5 @@ app.get('*', function (req, res) {
// Server
let server = app.listen(app.get('port'), app.get('address'), () => {
console.log(`Listening on: ${EnvConfig.ui.protocol}://${server.address().address}:${server.address().port}`);
console.log(`Listening on: ${EnvConfig.ui.ssl ? 'https://' : 'http://'}://${server.address().address}:${server.address().port}`);
});

View File

@@ -26,8 +26,10 @@ import { routes } from './server.routes';
import { EnvConfig } from './config';
if (EnvConfig.production) {
// enable prod for faster renders
enableProdMode();
}
const app = express();
const ROOT = path.join(path.resolve(__dirname, '..'));
@@ -116,5 +118,5 @@ app.get('*', function (req, res) {
// Server
let server = app.listen(app.get('port'), app.get('address'), () => {
console.log(`Listening on: ${EnvConfig.ui.protocol}://${server.address().address}:${server.address().port}`);
console.log(`Listening on: ${EnvConfig.ui.ssl ? 'https://' : 'http://'}://${server.address().address}:${server.address().port}`);
});

View File

@@ -94,7 +94,6 @@ export var clientConfig = {
}
};
// Server.
export var serverPlugins = [
@@ -133,9 +132,6 @@ export default [
webpackMerge(clone(commonConfig), serverConfig, { plugins: serverPlugins.concat(commonPlugins) })
];
// Helpers
export function includeClientPackages(packages, localModule?: string[]) {
return function(context, request, cb) {