Update to have a configuration file out of the
app bundle.
This commit is contained in:
@@ -25,10 +25,9 @@ export class AircraftService extends BaseService {
|
||||
imageData: dataImg
|
||||
};
|
||||
|
||||
this.http
|
||||
.post(`${this.apiUrl}/Aircraft`, bodyNewAircraft, {
|
||||
headers: this.headers
|
||||
})
|
||||
.subscribe(data => console.log(data));
|
||||
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() {
|
||||
this.headers = new HttpHeaders({
|
||||
'Access-Control-Allow-Origin': environment.apiUrl
|
||||
ConfigurationHelper.settings.subscribe(settings =>
|
||||
{
|
||||
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()
|
||||
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