From 68d8ea00d26b80e0bcab6ec19d179e3f8a1927f0 Mon Sep 17 00:00:00 2001 From: William Welling Date: Tue, 26 Sep 2017 20:11:56 -0500 Subject: [PATCH] functional base href from ui config namespace property --- src/app/app.module.ts | 12 ++++++++++-- src/app/core/url-combiner/rest-url-combiner.ts | 2 +- src/app/core/url-combiner/ui-url-combiner.ts | 2 +- src/config.ts | 6 +++--- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 0099e41245..55edd3e9ce 100755 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,5 +1,5 @@ import { NgModule } from '@angular/core'; -import { CommonModule } from '@angular/common'; +import { CommonModule, APP_BASE_HREF } from '@angular/common'; import { HttpModule } from '@angular/http'; import { FormsModule } from '@angular/forms'; import { RouterModule } from '@angular/router'; @@ -39,7 +39,11 @@ export function getConfig() { return ENV_CONFIG; } -export function getMetaReducers(config: GlobalConfig): MetaReducer[] { +export function getBase() { + return ENV_CONFIG.ui.nameSpace; +} + +export function getMetaReducers(config: GlobalConfig): Array> { return config.production ? appMetaReducers : [...appMetaReducers, storeFreeze]; } @@ -63,6 +67,10 @@ export function getMetaReducers(config: GlobalConfig): MetaReducer[] { provide: GLOBAL_CONFIG, useFactory: (getConfig) }, + { + provide: APP_BASE_HREF, + useFactory: (getBase) + }, { provide: META_REDUCERS, useFactory: getMetaReducers, diff --git a/src/app/core/url-combiner/rest-url-combiner.ts b/src/app/core/url-combiner/rest-url-combiner.ts index 0169115356..06561c2379 100644 --- a/src/app/core/url-combiner/rest-url-combiner.ts +++ b/src/app/core/url-combiner/rest-url-combiner.ts @@ -10,6 +10,6 @@ import { GlobalConfig } from '../../../config'; */ export class RESTURLCombiner extends URLCombiner { constructor(EnvConfig: GlobalConfig, ...parts: string[]) { - super(EnvConfig.rest.baseUrl, EnvConfig.rest.nameSpace, ...parts); + super(EnvConfig.rest.baseUrl, ...parts); } } diff --git a/src/app/core/url-combiner/ui-url-combiner.ts b/src/app/core/url-combiner/ui-url-combiner.ts index 415f19ce28..2ebb26bb76 100644 --- a/src/app/core/url-combiner/ui-url-combiner.ts +++ b/src/app/core/url-combiner/ui-url-combiner.ts @@ -9,6 +9,6 @@ import { GlobalConfig } from '../../../config'; */ export class UIURLCombiner extends URLCombiner { constructor(EnvConfig: GlobalConfig, ...parts: string[]) { - super(EnvConfig.ui.baseUrl, EnvConfig.ui.nameSpace, ...parts); + super(EnvConfig.ui.baseUrl, ...parts); } } diff --git a/src/config.ts b/src/config.ts index 12cb2274fb..0628a4d99b 100644 --- a/src/config.ts +++ b/src/config.ts @@ -77,7 +77,7 @@ function buildBaseUrls(): void { getProtocol(ENV_CONFIG[key].ssl), getHost(ENV_CONFIG[key].host), getPort(ENV_CONFIG[key].port), - getContextPath(ENV_CONFIG[key].contextPath) + getNameSpace(ENV_CONFIG[key].nameSpace) ].join(''); } } @@ -95,8 +95,8 @@ function getPort(port: number): string { return port ? (port !== 80 && port !== 443) ? ':' + port : '' : ''; } -function getContextPath(contextPath: string): string { - return contextPath ? '/' + contextPath : ''; +function getNameSpace(nameSpace: string): string { + return nameSpace ? nameSpace.charAt(0) === '/' ? nameSpace : '/' + nameSpace : ''; } function isDefined(value: any): boolean {