404
{{"404.page-not-found" | translate}}
-
+
{{"404.help" | translate}}
-
+
{{"404.link.home-page" | translate}}
diff --git a/src/app/pagenotfound/pagenotfound.component.ts b/src/app/pagenotfound/pagenotfound.component.ts
index f0e78be45b..e8537bc6b7 100644
--- a/src/app/pagenotfound/pagenotfound.component.ts
+++ b/src/app/pagenotfound/pagenotfound.component.ts
@@ -1,6 +1,5 @@
import { Component } from '@angular/core';
-
@Component({
selector: 'ds-pagenotfound',
styleUrls: ['./pagenotfound.component.css'],
diff --git a/src/config.ts b/src/config.ts
index 4736005cb5..78f6d11446 100644
--- a/src/config.ts
+++ b/src/config.ts
@@ -1,48 +1,16 @@
// Look in ./config folder for config
import { OpaqueToken } from '@angular/core';
-import * as path from 'path';
-
-let configContext = require.context("../config", false, /js$/);
-
-let EnvConfig: any = {};
-let EnvConfigFile: string;
-let DefaultConfig: any = {};
-
-try {
- DefaultConfig = configContext('./environment.default.js');
-} catch (e) {
- throw new Error(`Cannot find file "${path.resolve('config', './environment.default.js')}"`);
-}
-
-switch (process.env.NODE_ENV) {
- case 'prod':
- case 'production':
- EnvConfigFile = './environment.prod.js';
- break;
- case 'dev':
- case 'development':
- default:
- EnvConfigFile = './environment.dev.js';
-}
-try {
- EnvConfig = configContext(EnvConfigFile);
-} catch (e) {
- EnvConfig = {};
-}
-
-const GLOBAL_CONFIG = new OpaqueToken('config');
-
interface ServerConfig {
"nameSpace": string,
"protocol": string,
"address": string,
"port": number,
- "baseURL": string
+ "baseUrl": string
}
interface GlobalConfig {
- "production": string,
+ "production": boolean,
"rest": ServerConfig,
"ui": ServerConfig,
"cache": {
@@ -55,16 +23,55 @@ interface GlobalConfig {
}
}
-const config: GlobalConfig =
Object.assign(DefaultConfig, EnvConfig);
+const GLOBAL_CONFIG = new OpaqueToken('config');
-function buildURL(server: ServerConfig) {
- return [server.protocol, '://', server.address, (server.port !== 80) ? ':' + server.port : ''].join('');
+let configContext = require.context("../config", false, /js$/);
+
+let EnvConfig: GlobalConfig;
+let EnvConfigFile: string;
+
+let production: boolean = false;
+
+switch (process.env.NODE_ENV) {
+ case 'prod':
+ case 'production':
+ production = true;
+ EnvConfigFile = './environment.prod.js';
+ break;
+ case 'dev':
+ case 'development':
+ EnvConfigFile = './environment.dev.js';
+ break;
+ case 'test':
+ EnvConfigFile = './environment.test.js';
+ break;
+ default:
+ console.warn('Environment file not specified. Using default.')
}
-for (let key in config) {
- if (config[key].protocol && config[key].address && config[key].port) {
- config[key].baseURL = buildURL(config[key]);
+try {
+ EnvConfig = configContext('./environment.default.js');
+} catch (e) {
+ throw new Error("Cannot find file ./environment.default.js");
+}
+
+// if EnvConfigFile set try to get configs
+if(EnvConfigFile) {
+ try {
+ EnvConfig = Object.assign(EnvConfig, configContext(EnvConfigFile));
+ } catch (e) {
+ console.warn("Cannot find file " + EnvConfigFile);
}
}
-export { GLOBAL_CONFIG, GlobalConfig, config }
+// set base url if propery is object with protocol, 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('');
+ }
+}
+
+// set config for running in production
+EnvConfig.production = production;
+
+export { GLOBAL_CONFIG, GlobalConfig, EnvConfig }
diff --git a/src/platform/modules/browser.module.ts b/src/platform/modules/browser.module.ts
index 9245b9b299..9cb2178fd9 100755
--- a/src/platform/modules/browser.module.ts
+++ b/src/platform/modules/browser.module.ts
@@ -23,7 +23,7 @@ import { effects } from '../../app/app.effects';
import { Meta } from '../angular2-meta';
import { RehydrateStoreAction } from "../../app/store.actions";
-import { GLOBAL_CONFIG, config } from '../../config';
+import { GLOBAL_CONFIG, EnvConfig } from '../../config';
// import * as LRU from 'modern-lru';
@@ -72,7 +72,8 @@ export const UNIVERSAL_KEY = 'UNIVERSAL_CACHE';
effects
],
providers: [
- { provide: GLOBAL_CONFIG, useValue: config },
+ { provide: GLOBAL_CONFIG, useValue: EnvConfig },
+
{ provide: 'isBrowser', useValue: isBrowser },
{ provide: 'isNode', useValue: isNode },
diff --git a/src/platform/modules/node.module.ts b/src/platform/modules/node.module.ts
index 28d4b3c33e..7148855d4f 100755
--- a/src/platform/modules/node.module.ts
+++ b/src/platform/modules/node.module.ts
@@ -21,7 +21,7 @@ import { effects } from '../../app/app.effects';
// see https://github.com/angular/angular/pull/12322
import { Meta } from '../angular2-meta';
-import { GLOBAL_CONFIG, config } from '../../config';
+import { GLOBAL_CONFIG, EnvConfig } from '../../config';
export function createTranslateLoader(http: Http) {
return new TranslateStaticLoader(http, './assets/i18n', '.json');
@@ -63,8 +63,8 @@ export const UNIVERSAL_KEY = 'UNIVERSAL_CACHE';
effects
],
providers: [
- { provide: GLOBAL_CONFIG, useValue: config },
- { provide: 'res', useFactory: getResponse },
+ { provide: GLOBAL_CONFIG, useValue: EnvConfig },
+
{ provide: 'isBrowser', useValue: isBrowser },
{ provide: 'isNode', useValue: isNode },
diff --git a/src/server.aot.ts b/src/server.aot.ts
index 11c2143f52..c8aa6a4c9a 100644
--- a/src/server.aot.ts
+++ b/src/server.aot.ts
@@ -25,7 +25,7 @@ import { MainModuleNgFactory } from './platform/modules/node.module.ngfactory';
// Routes
import { routes } from './server.routes';
-import { config } from './config';
+import { EnvConfig } from './config';
// enable prod for faster renders
enableProdMode();
@@ -44,8 +44,9 @@ app.engine('.html', createEngine({
// stateless providers only since it's shared
]
}));
-app.set('port', process.env.PORT || 3000);
-app.set('address', process.env.ADDRESS || '127.0.0.1');
+
+app.set('port', process.env.PORT || EnvConfig.ui.port || 3000);
+app.set('address', process.env.ADDRESS || EnvConfig.ui.address || '127.0.0.1');
app.set('views', __dirname);
app.set('view engine', 'html');
app.set('json spaces', 2);
@@ -66,13 +67,13 @@ function cacheControl(req, res, next) {
res.header('Cache-Control', 'max-age=60');
next();
}
+
// Serve static files
app.use('/assets', cacheControl, express.static(path.join(__dirname, 'assets'), { maxAge: 30 }));
app.use('/styles', cacheControl, express.static(path.join(__dirname, 'styles'), { maxAge: 30 }));
app.use(cacheControl, express.static(path.join(ROOT, 'dist/client'), { index: false }));
-//
/////////////////////////
// ** Example API
// Notice API should be in a separate process
@@ -95,11 +96,11 @@ function ngApp(req, res) {
res,
// use this to determine what part of your app is slow only in development
// time: true,
- async: true,
- preboot: true,
- baseUrl: '/',
+ async: EnvConfig.universal.async,
+ preboot: EnvConfig.universal.preboot,
+ baseUrl: EnvConfig.ui.nameSpace,
requestUrl: req.originalUrl,
- originUrl: `http://${app.get('address')}:${app.get('port')}`
+ originUrl: EnvConfig.ui.baseUrl
});
});
@@ -114,7 +115,6 @@ routes.forEach(route => {
app.get(`/${route}/*`, ngApp);
});
-
app.get('*', function(req, res) {
res.setHeader('Content-Type', 'application/json');
var pojo = { status: 404, message: 'No Content' };
@@ -124,5 +124,5 @@ app.get('*', function(req, res) {
// Server
let server = app.listen(app.get('port'), app.get('address'), () => {
- console.log(`Listening on: http://${server.address().address}:${server.address().port}`);
+ console.log(`Listening on: ${EnvConfig.ui.protocol}://${server.address().address}:${server.address().port}`);
});
diff --git a/src/server.ts b/src/server.ts
index 94f84259f3..302462418e 100644
--- a/src/server.ts
+++ b/src/server.ts
@@ -24,7 +24,7 @@ import { MainModule } from './platform/modules/node.module';
// Routes
import { routes } from './server.routes';
-import { config } from './config';
+import { EnvConfig } from './config';
// enable prod for faster renders
enableProdMode();
@@ -42,8 +42,9 @@ app.engine('.html', createEngine({
// stateless providers only since it's shared
]
}));
-app.set('port', process.env.PORT || 3000);
-app.set('address', process.env.ADDRESS || '127.0.0.1');
+
+app.set('port', process.env.PORT || EnvConfig.ui.port || 3000);
+app.set('address', process.env.ADDRESS || EnvConfig.ui.address || '127.0.0.1');
app.set('views', __dirname);
app.set('view engine', 'html');
app.set('json spaces', 2);
@@ -59,13 +60,13 @@ function cacheControl(req, res, next) {
res.header('Cache-Control', 'max-age=60');
next();
}
+
// Serve static files
app.use('/assets', cacheControl, express.static(path.join(__dirname, 'assets'), { maxAge: 30 }));
app.use('/styles', cacheControl, express.static(path.join(__dirname, 'styles'), { maxAge: 30 }));
app.use(cacheControl, express.static(path.join(ROOT, 'dist/client'), { index: false }));
-//
/////////////////////////
// ** Example API
// Notice API should be in aseparate process
@@ -87,11 +88,11 @@ function ngApp(req, res) {
req,
res,
// time: true, // use this to determine what part of your app is slow only in development
- async: true,
- preboot: true,
- baseUrl: '/',
+ async: EnvConfig.universal.async,
+ preboot: EnvConfig.universal.preboot,
+ baseUrl: EnvConfig.ui.nameSpace,
requestUrl: req.originalUrl,
- originUrl: `http://${app.get('address')}:${app.get('port')}`
+ originUrl: EnvConfig.ui.baseUrl
});
});
@@ -115,5 +116,5 @@ app.get('*', function(req, res) {
// Server
let server = app.listen(app.get('port'), app.get('address'), () => {
- console.log(`Listening on: http://${server.address().address}:${server.address().port}`);
+ console.log(`Listening on: ${EnvConfig.ui.protocol}://${server.address().address}:${server.address().port}`);
});