Update to have a configuration file out of the
app bundle.
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
"polyfills": "src/polyfills.ts",
|
"polyfills": "src/polyfills.ts",
|
||||||
"assets": [
|
"assets": [
|
||||||
"src/assets",
|
"src/assets",
|
||||||
|
"src/config",
|
||||||
"src/favicon.ico"
|
"src/favicon.ico"
|
||||||
],
|
],
|
||||||
"styles": [
|
"styles": [
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"ng": "ng",
|
"ng": "ng",
|
||||||
"start": "ng serve",
|
"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",
|
"test": "ng test",
|
||||||
"lint": "ng lint",
|
"lint": "ng lint",
|
||||||
"e2e": "ng e2e"
|
"e2e": "ng e2e"
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ import { Component, OnInit } from "@angular/core";
|
|||||||
import { Router } from "@angular/router";
|
import { Router } from "@angular/router";
|
||||||
|
|
||||||
import { User } from "../models/user";
|
import { User } from "../models/user";
|
||||||
import { environment } from "../environments/environment";
|
|
||||||
|
|
||||||
import { AuthenticationService } from "../services/authentication.service";
|
import { AuthenticationService } from "../services/authentication.service";
|
||||||
import { ServiceComm } from "../services/service-comm.service";
|
import { ServiceComm } from "../services/service-comm.service";
|
||||||
|
import { ConfigurationHelper } from "../services/configuration-helper";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: "app-root",
|
selector: "app-root",
|
||||||
@@ -16,7 +16,7 @@ export class AppComponent implements OnInit {
|
|||||||
public title = "app";
|
public title = "app";
|
||||||
public showMenu = false;
|
public showMenu = false;
|
||||||
public currentUser: User;
|
public currentUser: User;
|
||||||
public version: string = environment.version;
|
public version: string;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private router: Router,
|
private router: Router,
|
||||||
@@ -26,6 +26,7 @@ export class AppComponent implements OnInit {
|
|||||||
this.authenticationService.currentUser.subscribe(
|
this.authenticationService.currentUser.subscribe(
|
||||||
x => (this.currentUser = x)
|
x => (this.currentUser = x)
|
||||||
);
|
);
|
||||||
|
//this.version = ConfigurationHelper.settings.version;
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { BrowserModule } from "@angular/platform-browser";
|
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 { RouterModule, Routes } from "@angular/router";
|
||||||
import { HttpClientModule, HTTP_INTERCEPTORS } from "@angular/common/http";
|
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 { RequestCache } from "../services/request-cache.service";
|
||||||
import { AuthGuardService } from "../services/auth-guard.service";
|
import { AuthGuardService } from "../services/auth-guard.service";
|
||||||
import { ImageService } from "../services/image.service";
|
import { ImageService } from "../services/image.service";
|
||||||
|
import { ConfigurationHelper } from "../services/configuration-helper";
|
||||||
|
|
||||||
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
|
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
|
||||||
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
|
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
|
||||||
@@ -107,9 +108,14 @@ const appRoutes: Routes = [
|
|||||||
|
|
||||||
{ path: "login", component: LoginComponent },
|
{ 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({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
AppComponent,
|
AppComponent,
|
||||||
@@ -136,7 +142,6 @@ const appRoutes: Routes = [
|
|||||||
RouterModule.forRoot(
|
RouterModule.forRoot(
|
||||||
appRoutes,
|
appRoutes,
|
||||||
{ enableTracing: !environment.production, relativeLinkResolution: 'legacy' } // <-- debugging purposes only
|
{ enableTracing: !environment.production, relativeLinkResolution: 'legacy' } // <-- debugging purposes only
|
||||||
// <-- debugging purposes only
|
|
||||||
),
|
),
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
FormsModule,
|
FormsModule,
|
||||||
@@ -172,10 +177,13 @@ const appRoutes: Routes = [
|
|||||||
ServiceComm,
|
ServiceComm,
|
||||||
DateService,
|
DateService,
|
||||||
RequestCache,
|
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: JwtAuthInterceptor, multi: true },
|
||||||
{ provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true },
|
{ provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true },
|
||||||
|
// { provide: HTTP_INTERCEPTORS, useClass: CachingInterceptor, multi: true }
|
||||||
],
|
],
|
||||||
bootstrap: [AppComponent],
|
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 = {
|
export const environment = {
|
||||||
production: true,
|
production: true,
|
||||||
apiUrl: "https://divelog.sebastienandre.com",
|
|
||||||
debugMode: false,
|
debugMode: false,
|
||||||
version: "0.7.0",
|
env: "prod"
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
export const environment = {
|
export const environment = {
|
||||||
production: false,
|
production: false,
|
||||||
apiUrl: "http://localhost:5000",
|
debugMode: true,
|
||||||
debugMode: false,
|
env: "dev"
|
||||||
version: "0.?.0",
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
} from '@angular/common/http';
|
} from '@angular/common/http';
|
||||||
|
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
import { startWith, tap } from 'rxjs/operators';
|
import { tap } from 'rxjs/operators';
|
||||||
import 'rxjs/add/observable/of';
|
import 'rxjs/add/observable/of';
|
||||||
|
|
||||||
import { RequestCache } from '../services/request-cache.service';
|
import { RequestCache } from '../services/request-cache.service';
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { AuthenticationService } from "../services/authentication.service";
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class JwtAuthInterceptor implements HttpInterceptor {
|
export class JwtAuthInterceptor implements HttpInterceptor {
|
||||||
|
|
||||||
constructor(private authenticationService: AuthenticationService) {}
|
constructor(private authenticationService: AuthenticationService) {}
|
||||||
|
|
||||||
intercept(
|
intercept(
|
||||||
|
|||||||
@@ -10,4 +10,4 @@ if (environment.production) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
platformBrowserDynamic().bootstrapModule(AppModule)
|
platformBrowserDynamic().bootstrapModule(AppModule)
|
||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
|
|||||||
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
|
imageData: dataImg
|
||||||
};
|
};
|
||||||
|
|
||||||
this.http
|
this.http.post(`${this.apiUrl}/Aircraft`,
|
||||||
.post(`${this.apiUrl}/Aircraft`, bodyNewAircraft, {
|
bodyNewAircraft,
|
||||||
headers: this.headers
|
{ headers: this.headers })
|
||||||
})
|
.subscribe(data => console.log(data));
|
||||||
.subscribe(data => console.log(data));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,8 @@ import { map } from "rxjs/operators";
|
|||||||
import { User } from "../models/user";
|
import { User } from "../models/user";
|
||||||
import { BaseService } from "./base.service";
|
import { BaseService } from "./base.service";
|
||||||
|
|
||||||
@Injectable({
|
|
||||||
providedIn: "root"
|
@Injectable({ providedIn: "root" })
|
||||||
})
|
|
||||||
export class AuthenticationService extends BaseService {
|
export class AuthenticationService extends BaseService {
|
||||||
private currentUserSubject: BehaviorSubject<User>;
|
private currentUserSubject: BehaviorSubject<User>;
|
||||||
public currentUser: Observable<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 { HttpHeaders } from '@angular/common/http';
|
||||||
import { environment } from '../environments/environment';
|
|
||||||
|
|
||||||
|
import { ConfigurationHelper } from './configuration-helper';
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class BaseService {
|
export class BaseService {
|
||||||
protected readonly headers: HttpHeaders;
|
protected headers: HttpHeaders;
|
||||||
protected readonly apiUrl: string;
|
protected apiUrl: string;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.headers = new HttpHeaders({
|
ConfigurationHelper.settings.subscribe(settings =>
|
||||||
'Access-Control-Allow-Origin': environment.apiUrl
|
{
|
||||||
|
let tmpApiUrl : string = settings.apiUrl;
|
||||||
|
|
||||||
|
this.headers = new HttpHeaders({
|
||||||
|
'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()
|
@Injectable()
|
||||||
export class ServiceComm {
|
export class ServiceComm {
|
||||||
private componentTitleSource = new BehaviorSubject<string>('');
|
private componentTitleSource = new BehaviorSubject<string>('');
|
||||||
componentTitle = this.componentTitleSource.asObservable();
|
public componentTitle = this.componentTitleSource.asObservable();
|
||||||
|
|
||||||
private refreshRequestSource = new BehaviorSubject<AddAction>(AddAction.None);
|
private refreshRequestSource = new BehaviorSubject<AddAction>(AddAction.None);
|
||||||
refreshRequest = this.refreshRequestSource.asObservable();
|
public refreshRequest = this.refreshRequestSource.asObservable();
|
||||||
|
|
||||||
constructor() { }
|
constructor() { }
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable, Injector } from '@angular/core';
|
||||||
import { HttpClient } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
|
|||||||
Reference in New Issue
Block a user