mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 15:03:07 +00:00
Add a mechanism to configure environment variables.
This commit is contained in:
@@ -4,6 +4,9 @@
|
||||
<main>
|
||||
<p>{{ 'example.with.data' | translate:data }}</p>
|
||||
<p>{{ example }}</p>
|
||||
<p><b>{{ title }}</b></p>
|
||||
<h2 *ngIf="!env" style="color:green">development</h2>
|
||||
<h2 *ngIf="env" style="color:red">production</h2>
|
||||
<router-outlet></router-outlet>
|
||||
</main>
|
||||
</div>
|
||||
|
@@ -9,6 +9,7 @@ import { TranslateService } from "ng2-translate";
|
||||
import { HostWindowState } from "./shared/host-window.reducer";
|
||||
import { Store } from "@ngrx/store";
|
||||
import { HostWindowActions } from "./shared/host-window.actions";
|
||||
import { GlobalConfig } from "../config";
|
||||
|
||||
@Component({
|
||||
changeDetection: ChangeDetectionStrategy.Default,
|
||||
@@ -27,6 +28,13 @@ export class AppComponent implements OnDestroy, OnInit {
|
||||
recipient: 'World'
|
||||
};
|
||||
|
||||
title: string = GlobalConfig.title;
|
||||
env: string = GlobalConfig.production;
|
||||
|
||||
styles = {
|
||||
color: 'red'
|
||||
};
|
||||
|
||||
constructor(
|
||||
private translate: TranslateService,
|
||||
private store: Store<HostWindowState>
|
||||
@@ -51,6 +59,7 @@ export class AppComponent implements OnDestroy, OnInit {
|
||||
|
||||
@HostListener('window:resize', ['$event'])
|
||||
private onResize(event): void {
|
||||
console.log(GlobalConfig.rest.baseURL);
|
||||
this.store.dispatch(
|
||||
HostWindowActions.resize(event.target.innerWidth, event.target.innerHeight)
|
||||
);
|
||||
|
34
src/config.ts
Normal file
34
src/config.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
// Look in ./config folder for config
|
||||
|
||||
const path = require('path');
|
||||
|
||||
let configContext = require.context("../config", false, /json$/);
|
||||
let EnvConfig : any = {};
|
||||
let EnvConfigFile : string;
|
||||
let CommonConfig : any = {};
|
||||
|
||||
try {
|
||||
CommonConfig = configContext('./environment.common.json');
|
||||
} catch (e) {
|
||||
throw new Error(`Cannot find file "${path.resolve('config', './environment.common.json')}"`);
|
||||
}
|
||||
|
||||
switch (process.env.NODE_ENV) {
|
||||
case 'prod':
|
||||
case 'production':
|
||||
EnvConfigFile = './environment.prod.json';
|
||||
break;
|
||||
case 'dev':
|
||||
case 'development':
|
||||
default:
|
||||
EnvConfigFile = './environment.dev.json';
|
||||
}
|
||||
try {
|
||||
EnvConfig = configContext(EnvConfigFile);
|
||||
} catch (e) {
|
||||
throw new Error(`Cannot find file "${path.resolve('config', EnvConfigFile)}"`);
|
||||
}
|
||||
|
||||
const GlobalConfig = Object.assign(CommonConfig, EnvConfig);
|
||||
|
||||
export {GlobalConfig}
|
Reference in New Issue
Block a user