Update to have a configuration file out of the
app bundle.
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
"polyfills": "src/polyfills.ts",
|
||||
"assets": [
|
||||
"src/assets",
|
||||
"src/config",
|
||||
"src/favicon.ico"
|
||||
],
|
||||
"styles": [
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"scripts": {
|
||||
"ng": "ng",
|
||||
"start": "ng serve",
|
||||
"build": "ng build --prod=true --build-optimizer --aot=true --extractCss=true --optimization=true --progress=true --sourceMap=false",
|
||||
"build": "ng build --prod=true --build-optimizer --aot=true --optimization=true --progress=true --sourceMap=false",
|
||||
"test": "ng test",
|
||||
"lint": "ng lint",
|
||||
"e2e": "ng e2e"
|
||||
|
||||
@@ -2,10 +2,10 @@ import { Component, OnInit } from "@angular/core";
|
||||
import { Router } from "@angular/router";
|
||||
|
||||
import { User } from "../models/user";
|
||||
import { environment } from "../environments/environment";
|
||||
|
||||
import { AuthenticationService } from "../services/authentication.service";
|
||||
import { ServiceComm } from "../services/service-comm.service";
|
||||
import { ConfigurationHelper } from "../services/configuration-helper";
|
||||
|
||||
@Component({
|
||||
selector: "app-root",
|
||||
@@ -16,7 +16,7 @@ export class AppComponent implements OnInit {
|
||||
public title = "app";
|
||||
public showMenu = false;
|
||||
public currentUser: User;
|
||||
public version: string = environment.version;
|
||||
public version: string;
|
||||
|
||||
constructor(
|
||||
private router: Router,
|
||||
@@ -26,6 +26,7 @@ export class AppComponent implements OnInit {
|
||||
this.authenticationService.currentUser.subscribe(
|
||||
x => (this.currentUser = x)
|
||||
);
|
||||
//this.version = ConfigurationHelper.settings.version;
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { BrowserModule } from "@angular/platform-browser";
|
||||
import { NgModule } from "@angular/core";
|
||||
import { APP_INITIALIZER, NgModule } from "@angular/core";
|
||||
import { RouterModule, Routes } from "@angular/router";
|
||||
import { HttpClientModule, HTTP_INTERCEPTORS } from "@angular/common/http";
|
||||
|
||||
@@ -33,6 +33,7 @@ import { ServiceComm } from "../services/service-comm.service";
|
||||
import { RequestCache } from "../services/request-cache.service";
|
||||
import { AuthGuardService } from "../services/auth-guard.service";
|
||||
import { ImageService } from "../services/image.service";
|
||||
import { ConfigurationHelper } from "../services/configuration-helper";
|
||||
|
||||
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
|
||||
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
|
||||
@@ -107,9 +108,14 @@ const appRoutes: Routes = [
|
||||
|
||||
{ path: "login", component: LoginComponent },
|
||||
|
||||
{ path: "**", redirectTo: "" },
|
||||
//{ path: "**", redirectTo: "" },
|
||||
];
|
||||
|
||||
// Déclaration de la fonction d'initialisation de la configuration
|
||||
export function initConfig(configService: ConfigurationHelper) {
|
||||
return () => configService.load(environment.env);
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
AppComponent,
|
||||
@@ -136,7 +142,6 @@ const appRoutes: Routes = [
|
||||
RouterModule.forRoot(
|
||||
appRoutes,
|
||||
{ enableTracing: !environment.production, relativeLinkResolution: 'legacy' } // <-- debugging purposes only
|
||||
// <-- debugging purposes only
|
||||
),
|
||||
ReactiveFormsModule,
|
||||
FormsModule,
|
||||
@@ -172,10 +177,13 @@ const appRoutes: Routes = [
|
||||
ServiceComm,
|
||||
DateService,
|
||||
RequestCache,
|
||||
// { provide: HTTP_INTERCEPTORS, useClass: CachingInterceptor, multi: true }
|
||||
ConfigurationHelper,
|
||||
{ provide: APP_INITIALIZER, useFactory: initConfig, deps: [ConfigurationHelper], multi: true },
|
||||
{ provide: HTTP_INTERCEPTORS, useClass: JwtAuthInterceptor, multi: true },
|
||||
{ provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true },
|
||||
// { provide: HTTP_INTERCEPTORS, useClass: CachingInterceptor, multi: true }
|
||||
],
|
||||
bootstrap: [AppComponent],
|
||||
})
|
||||
export class AppModule {}
|
||||
export class AppModule {
|
||||
}
|
||||
|
||||
4
Front/skydivelogs-app/src/config/config.dev.json
Normal file
4
Front/skydivelogs-app/src/config/config.dev.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"apiUrl": "http://localhost:5000",
|
||||
"version": "0.28.0"
|
||||
}
|
||||
4
Front/skydivelogs-app/src/config/config.prod.json
Normal file
4
Front/skydivelogs-app/src/config/config.prod.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"apiUrl": "https://test-divelog.sebastienandre.com",
|
||||
"version": "0.28.0"
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
export const environment = {
|
||||
production: true,
|
||||
apiUrl: "https://divelog.sebastienandre.com",
|
||||
debugMode: false,
|
||||
version: "0.7.0",
|
||||
env: "prod"
|
||||
};
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
export const environment = {
|
||||
production: false,
|
||||
apiUrl: "http://localhost:5000",
|
||||
debugMode: false,
|
||||
version: "0.?.0",
|
||||
debugMode: true,
|
||||
env: "dev"
|
||||
};
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
} from '@angular/common/http';
|
||||
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { startWith, tap } from 'rxjs/operators';
|
||||
import { tap } from 'rxjs/operators';
|
||||
import 'rxjs/add/observable/of';
|
||||
|
||||
import { RequestCache } from '../services/request-cache.service';
|
||||
|
||||
@@ -11,6 +11,7 @@ import { AuthenticationService } from "../services/authentication.service";
|
||||
|
||||
@Injectable()
|
||||
export class JwtAuthInterceptor implements HttpInterceptor {
|
||||
|
||||
constructor(private authenticationService: AuthenticationService) {}
|
||||
|
||||
intercept(
|
||||
|
||||
4
Front/skydivelogs-app/src/models/app-settings.ts
Normal file
4
Front/skydivelogs-app/src/models/app-settings.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export interface IAppSettings {
|
||||
apiUrl: string;
|
||||
version: string;
|
||||
}
|
||||
@@ -25,10 +25,9 @@ export class AircraftService extends BaseService {
|
||||
imageData: dataImg
|
||||
};
|
||||
|
||||
this.http
|
||||
.post(`${this.apiUrl}/Aircraft`, bodyNewAircraft, {
|
||||
headers: this.headers
|
||||
})
|
||||
this.http.post(`${this.apiUrl}/Aircraft`,
|
||||
bodyNewAircraft,
|
||||
{ headers: this.headers })
|
||||
.subscribe(data => console.log(data));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,8 @@ import { map } from "rxjs/operators";
|
||||
import { User } from "../models/user";
|
||||
import { BaseService } from "./base.service";
|
||||
|
||||
@Injectable({
|
||||
providedIn: "root"
|
||||
})
|
||||
|
||||
@Injectable({ providedIn: "root" })
|
||||
export class AuthenticationService extends BaseService {
|
||||
private currentUserSubject: BehaviorSubject<User>;
|
||||
public currentUser: Observable<User>;
|
||||
|
||||
@@ -1,18 +1,32 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Injector } from '@angular/core';
|
||||
import { HttpHeaders } from '@angular/common/http';
|
||||
import { environment } from '../environments/environment';
|
||||
|
||||
import { ConfigurationHelper } from './configuration-helper';
|
||||
|
||||
@Injectable()
|
||||
export class BaseService {
|
||||
protected readonly headers: HttpHeaders;
|
||||
protected readonly apiUrl: string;
|
||||
protected headers: HttpHeaders;
|
||||
protected apiUrl: string;
|
||||
|
||||
constructor() {
|
||||
ConfigurationHelper.settings.subscribe(settings =>
|
||||
{
|
||||
let tmpApiUrl : string = settings.apiUrl;
|
||||
|
||||
this.headers = new HttpHeaders({
|
||||
'Access-Control-Allow-Origin': environment.apiUrl
|
||||
'Access-Control-Allow-Origin': tmpApiUrl
|
||||
});
|
||||
this.apiUrl = tmpApiUrl + '/api';
|
||||
});
|
||||
|
||||
this.apiUrl = environment.apiUrl + '/api';
|
||||
// const config: ConfigurationHelper = injector.get(ConfigurationHelper);
|
||||
// config.load(environment.env)
|
||||
// .then(() => {
|
||||
// let tmpApiUrl : string = ConfigurationHelper.settings.apiUrl;
|
||||
|
||||
// this.headers = new HttpHeaders({
|
||||
// 'Access-Control-Allow-Origin': tmpApiUrl
|
||||
// });
|
||||
// this.apiUrl = tmpApiUrl + '/api';
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
32
Front/skydivelogs-app/src/services/configuration-helper.ts
Normal file
32
Front/skydivelogs-app/src/services/configuration-helper.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
|
||||
import { IAppSettings } from '../models/app-settings';
|
||||
|
||||
|
||||
@Injectable({ providedIn: "root" })
|
||||
export class ConfigurationHelper {
|
||||
private static settingsSource = new BehaviorSubject<IAppSettings>();
|
||||
public static settings = ConfigurationHelper.settingsSource.asObservable();
|
||||
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
load(env: string) {
|
||||
const jsonFile = `/config/config.${env}.json`;
|
||||
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
this.http.get(jsonFile)
|
||||
.toPromise()
|
||||
.then((response : IAppSettings) => {
|
||||
//ConfigurationHelper.settings = <IAppSettings>response;
|
||||
ConfigurationHelper.settingsSource.next(<IAppSettings>response);
|
||||
resolve();
|
||||
})
|
||||
.catch((response: any) => {
|
||||
reject(`Could not load file '${jsonFile}': ${JSON.stringify(response)}`);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,10 @@ import { AddAction } from '../models/add-action.enum';
|
||||
@Injectable()
|
||||
export class ServiceComm {
|
||||
private componentTitleSource = new BehaviorSubject<string>('');
|
||||
componentTitle = this.componentTitleSource.asObservable();
|
||||
public componentTitle = this.componentTitleSource.asObservable();
|
||||
|
||||
private refreshRequestSource = new BehaviorSubject<AddAction>(AddAction.None);
|
||||
refreshRequest = this.refreshRequestSource.asObservable();
|
||||
public refreshRequest = this.refreshRequestSource.asObservable();
|
||||
|
||||
constructor() { }
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Injectable, Injector } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
Reference in New Issue
Block a user