diff options
-rw-r--r-- | frontend/src/app/_data/IConfig.ts | 4 | ||||
-rw-r--r-- | frontend/src/app/_services/auth.service.ts | 10 | ||||
-rw-r--r-- | frontend/src/app/_services/datasets.service.ts | 14 | ||||
-rw-r--r-- | frontend/src/app/_services/experiments.service.ts | 6 | ||||
-rw-r--r-- | frontend/src/app/_services/models.service.ts | 19 | ||||
-rw-r--r-- | frontend/src/app/_services/predictors.service.ts | 15 | ||||
-rw-r--r-- | frontend/src/app/_services/signal-r.service.ts | 4 | ||||
-rw-r--r-- | frontend/src/app/_services/user-info.service.ts | 10 | ||||
-rw-r--r-- | frontend/src/app/app.module.ts | 15 | ||||
-rw-r--r-- | frontend/src/app/configuration.service.spec.ts | 16 | ||||
-rw-r--r-- | frontend/src/app/configuration.service.ts | 20 | ||||
-rw-r--r-- | frontend/src/assets/config.json | 4 | ||||
-rw-r--r-- | frontend/src/config.json | 4 | ||||
-rw-r--r-- | production/app/config.json | 3 | ||||
-rw-r--r-- | production/app/main.js | 2 |
15 files changed, 95 insertions, 51 deletions
diff --git a/frontend/src/app/_data/IConfig.ts b/frontend/src/app/_data/IConfig.ts new file mode 100644 index 00000000..238f55f6 --- /dev/null +++ b/frontend/src/app/_data/IConfig.ts @@ -0,0 +1,4 @@ +export interface IConfig { + apiURL: string; + apiWSUrl: string; +}
\ No newline at end of file diff --git a/frontend/src/app/_services/auth.service.ts b/frontend/src/app/_services/auth.service.ts index e474d436..92cebe7f 100644 --- a/frontend/src/app/_services/auth.service.ts +++ b/frontend/src/app/_services/auth.service.ts @@ -2,8 +2,8 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { JwtHelperService } from '@auth0/angular-jwt'; import { CookieService } from 'ngx-cookie-service'; -import API_SETTINGS from '../../config.json'; import shared from '../Shared'; +import { Configuration } from '../configuration.service'; const jwtHelper = new JwtHelperService(); @@ -17,15 +17,15 @@ export class AuthService { constructor(private http: HttpClient, private cookie: CookieService) { } login(username: string, password: string) { - return this.http.post(`${API_SETTINGS.apiURL}/auth/login`, { username, password }, { responseType: 'text' }); + return this.http.post(`${Configuration.settings.apiURL}/auth/login`, { username, password }, { responseType: 'text' }); } register(user: any) { - return this.http.post(`${API_SETTINGS.apiURL}/auth/register`, { ...user }, { responseType: 'text' }); + return this.http.post(`${Configuration.settings.apiURL}/auth/register`, { ...user }, { responseType: 'text' }); } getGuestToken() { - return this.http.post(`${API_SETTINGS.apiURL}/auth/guestToken`, {}, { responseType: 'text' }); + return this.http.post(`${Configuration.settings.apiURL}/auth/guestToken`, {}, { responseType: 'text' }); } isAuthenticated(): boolean { @@ -52,7 +52,7 @@ export class AuthService { var username = property['name']; if (username != "") { this.refresher = setTimeout(() => { - this.http.post(`${API_SETTINGS.apiURL}/auth/renewJwt`, {}, { headers: this.authHeader(), responseType: 'text' }).subscribe((response) => { + this.http.post(`${Configuration.settings.apiURL}/auth/renewJwt`, {}, { headers: this.authHeader(), responseType: 'text' }).subscribe((response) => { this.authenticate(response); }); }, exp.getTime() - new Date().getTime() - 60000); diff --git a/frontend/src/app/_services/datasets.service.ts b/frontend/src/app/_services/datasets.service.ts index 9a718e7c..c3281be6 100644 --- a/frontend/src/app/_services/datasets.service.ts +++ b/frontend/src/app/_services/datasets.service.ts @@ -1,7 +1,7 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; -import API_SETTINGS from '../../config.json'; +import { Configuration } from '../configuration.service'; import Dataset from '../_data/Dataset'; import { AuthService } from './auth.service'; @@ -13,26 +13,26 @@ export class DatasetsService { constructor(private http: HttpClient, private authService: AuthService) { } getPublicDatasets(): Observable<Dataset[]> { - return this.http.get<Dataset[]>(`${API_SETTINGS.apiURL}/dataset/publicdatasets`, { headers: this.authService.authHeader() }); + return this.http.get<Dataset[]>(`${Configuration.settings.apiURL}/dataset/publicdatasets`, { headers: this.authService.authHeader() }); } getMyDatasets(): Observable<Dataset[]> { - return this.http.get<Dataset[]>(`${API_SETTINGS.apiURL}/dataset/mydatasets`, { headers: this.authService.authHeader() }); + return this.http.get<Dataset[]>(`${Configuration.settings.apiURL}/dataset/mydatasets`, { headers: this.authService.authHeader() }); } addDataset(dataset: Dataset): Observable<any> { - return this.http.post(`${API_SETTINGS.apiURL}/dataset/add`, dataset, { headers: this.authService.authHeader() }); + return this.http.post(`${Configuration.settings.apiURL}/dataset/add`, dataset, { headers: this.authService.authHeader() }); } getDatasetFile(fileId: any): any { - return this.http.get(`${API_SETTINGS.apiURL}/file/csvRead/true/${fileId}`, { headers: this.authService.authHeader(), responseType: 'text' }); + return this.http.get(`${Configuration.settings.apiURL}/file/csvRead/true/${fileId}`, { headers: this.authService.authHeader(), responseType: 'text' }); } editDataset(dataset: Dataset): Observable<Dataset> { - return this.http.put<Dataset>(`${API_SETTINGS.apiURL}/dataset/`, dataset, { headers: this.authService.authHeader() }); + return this.http.put<Dataset>(`${Configuration.settings.apiURL}/dataset/`, dataset, { headers: this.authService.authHeader() }); } deleteDataset(dataset: Dataset) { - return this.http.delete(`${API_SETTINGS.apiURL}/dataset/` + dataset.name, { headers: this.authService.authHeader(), responseType: "text" }); + return this.http.delete(`${Configuration.settings.apiURL}/dataset/` + dataset.name, { headers: this.authService.authHeader(), responseType: "text" }); } } diff --git a/frontend/src/app/_services/experiments.service.ts b/frontend/src/app/_services/experiments.service.ts index 7462cd14..0d0d372b 100644 --- a/frontend/src/app/_services/experiments.service.ts +++ b/frontend/src/app/_services/experiments.service.ts @@ -1,7 +1,7 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; -import API_SETTINGS from '../../config.json'; +import { Configuration } from '../configuration.service'; import Experiment from '../_data/Experiment'; import { AuthService } from './auth.service'; @@ -13,10 +13,10 @@ export class ExperimentsService { constructor(private http: HttpClient, private authService: AuthService) { } addExperiment(experiment: Experiment): Observable<any> { - return this.http.post(`${API_SETTINGS.apiURL}/experiment/add`, experiment, { headers: this.authService.authHeader() }); + return this.http.post(`${Configuration.settings.apiURL}/experiment/add`, experiment, { headers: this.authService.authHeader() }); } getMyExperiments(): Observable<Experiment[]> { - return this.http.get<Experiment[]>(`${API_SETTINGS.apiURL}/experiment/getmyexperiments`, { headers: this.authService.authHeader() }); + return this.http.get<Experiment[]>(`${Configuration.settings.apiURL}/experiment/getmyexperiments`, { headers: this.authService.authHeader() }); } } diff --git a/frontend/src/app/_services/models.service.ts b/frontend/src/app/_services/models.service.ts index 1314589a..44383828 100644 --- a/frontend/src/app/_services/models.service.ts +++ b/frontend/src/app/_services/models.service.ts @@ -2,10 +2,9 @@ import { HttpClient, HttpParams } from '@angular/common/http'; import { Injectable } from '@angular/core'; import Model from '../_data/Model'; import { AuthService } from './auth.service'; -import API_SETTINGS from '../../config.json'; import { Observable } from 'rxjs'; import Dataset from '../_data/Dataset'; - +import { Configuration } from '../configuration.service'; @Injectable({ providedIn: 'root' @@ -26,32 +25,32 @@ export class ModelsService { headers: this.authService.authHeader() }; - return this.http.post(`${API_SETTINGS.apiURL}/file/csv`, formData, options); + return this.http.post(`${Configuration.settings.apiURL}/file/csv`, formData, options); } addModel(model: Model): Observable<any> { - return this.http.post(`${API_SETTINGS.apiURL}/model/add`, model, { headers: this.authService.authHeader() }); + return this.http.post(`${Configuration.settings.apiURL}/model/add`, model, { headers: this.authService.authHeader() }); } addDataset(dataset: Dataset): Observable<any> { - return this.http.post(`${API_SETTINGS.apiURL}/dataset/add`, dataset, { headers: this.authService.authHeader() }); + return this.http.post(`${Configuration.settings.apiURL}/dataset/add`, dataset, { headers: this.authService.authHeader() }); } trainModel(modelId: string, experimentId: string): Observable<any> { - return this.http.post(`${API_SETTINGS.apiURL}/model/trainmodel`, { ModelId: modelId, ExperimentId: experimentId }, { headers: this.authService.authHeader(), responseType: 'text' }); + return this.http.post(`${Configuration.settings.apiURL}/model/trainmodel`, { ModelId: modelId, ExperimentId: experimentId }, { headers: this.authService.authHeader(), responseType: 'text' }); } getMyDatasets(): Observable<Dataset[]> { - return this.http.get<Dataset[]>(`${API_SETTINGS.apiURL}/dataset/mydatasets`, { headers: this.authService.authHeader() }); + return this.http.get<Dataset[]>(`${Configuration.settings.apiURL}/dataset/mydatasets`, { headers: this.authService.authHeader() }); } getMyModels(): Observable<Model[]> { - return this.http.get<Model[]>(`${API_SETTINGS.apiURL}/model/mymodels`, { headers: this.authService.authHeader() }); + return this.http.get<Model[]>(`${Configuration.settings.apiURL}/model/mymodels`, { headers: this.authService.authHeader() }); } editModel(model: Model): Observable<Model> { - return this.http.put<Model>(`${API_SETTINGS.apiURL}/model/`, model, { headers: this.authService.authHeader() }); + return this.http.put<Model>(`${Configuration.settings.apiURL}/model/`, model, { headers: this.authService.authHeader() }); } deleteModel(model: Model) { - return this.http.delete(`${API_SETTINGS.apiURL}/model/` + model.name, { headers: this.authService.authHeader(), responseType: "text" }); + return this.http.delete(`${Configuration.settings.apiURL}/model/` + model.name, { headers: this.authService.authHeader(), responseType: "text" }); } } diff --git a/frontend/src/app/_services/predictors.service.ts b/frontend/src/app/_services/predictors.service.ts index 909d1a49..9e8383aa 100644 --- a/frontend/src/app/_services/predictors.service.ts +++ b/frontend/src/app/_services/predictors.service.ts @@ -1,7 +1,7 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; -import API_SETTINGS from '../../config.json'; +import { Configuration } from '../configuration.service'; import Predictor from '../_data/Predictor'; import { Column } from '../_pages/predict/predict.component'; import { AuthService } from './auth.service'; @@ -10,27 +10,24 @@ import { AuthService } from './auth.service'; providedIn: 'root' }) export class PredictorsService { - - - constructor(private http: HttpClient, private authService: AuthService) { } getPublicPredictors(): Observable<Predictor[]> { - return this.http.get<Predictor[]>(`${API_SETTINGS.apiURL}/predictor/publicpredictors`, { headers: this.authService.authHeader() }); + return this.http.get<Predictor[]>(`${Configuration.settings.apiURL}/predictor/publicpredictors`, { headers: this.authService.authHeader() }); } getPredictor(id: String): Observable<Predictor> { - return this.http.get<Predictor>(`${API_SETTINGS.apiURL}/predictor/getpredictor/` + id, { headers: this.authService.authHeader() }); + return this.http.get<Predictor>(`${Configuration.settings.apiURL}/predictor/getpredictor/` + id, { headers: this.authService.authHeader() }); } usePredictor(predictor: Predictor, inputs: Column[]) { - return this.http.post(`${API_SETTINGS.apiURL}/predictor/usepredictor/` + predictor._id, inputs, { headers: this.authService.authHeader() }); + return this.http.post(`${Configuration.settings.apiURL}/predictor/usepredictor/` + predictor._id, inputs, { headers: this.authService.authHeader() }); } deletePredictor(predictor: Predictor) { - return this.http.delete(`${API_SETTINGS.apiURL}/predictor/` + predictor.name, { headers: this.authService.authHeader(), responseType: "text" }); + return this.http.delete(`${Configuration.settings.apiURL}/predictor/` + predictor.name, { headers: this.authService.authHeader(), responseType: "text" }); } getMyPredictors(): Observable<Predictor[]> { - return this.http.get<Predictor[]>(`${API_SETTINGS.apiURL}/predictor/mypredictors`, { headers: this.authService.authHeader() }); + return this.http.get<Predictor[]>(`${Configuration.settings.apiURL}/predictor/mypredictors`, { headers: this.authService.authHeader() }); } } diff --git a/frontend/src/app/_services/signal-r.service.ts b/frontend/src/app/_services/signal-r.service.ts index 2a6e5d78..b279b5ca 100644 --- a/frontend/src/app/_services/signal-r.service.ts +++ b/frontend/src/app/_services/signal-r.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import * as signalR from "@microsoft/signalr"; -import Shared from '../Shared'; import { CookieService } from 'ngx-cookie-service'; +import { Configuration } from '../configuration.service'; @Injectable({ providedIn: 'root' }) @@ -10,7 +10,7 @@ export class SignalRService { public startConnection = () => { this.hubConnection = new signalR.HubConnectionBuilder() - .withUrl('http://localhost:5283/chatHub', { + .withUrl(Configuration.settings.apiWSUrl, { accessTokenFactory: () => this.cookie.get("token"), withCredentials: false }).build(); diff --git a/frontend/src/app/_services/user-info.service.ts b/frontend/src/app/_services/user-info.service.ts index 16fc90a2..5d3394f6 100644 --- a/frontend/src/app/_services/user-info.service.ts +++ b/frontend/src/app/_services/user-info.service.ts @@ -1,7 +1,7 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; -import API_SETTINGS from '../../config.json'; +import { Configuration } from '../configuration.service'; import User from '../_data/User'; import { AuthService } from './auth.service'; @@ -13,18 +13,18 @@ export class UserInfoService { constructor(private http: HttpClient, private authService: AuthService) { } getUserInfo(): Observable<User> { - return this.http.get<User>(`${API_SETTINGS.apiURL}/user/myprofile`, { headers: this.authService.authHeader() }); + return this.http.get<User>(`${Configuration.settings.apiURL}/user/myprofile`, { headers: this.authService.authHeader() }); } changeUserInfo(user: User): any { - return this.http.put(`${API_SETTINGS.apiURL}/user/changeinfo`, user, { headers: this.authService.authHeader() }); + return this.http.put(`${Configuration.settings.apiURL}/user/changeinfo`, user, { headers: this.authService.authHeader() }); } changeUserPassword(passwordArray: string[]): any { - return this.http.put(`${API_SETTINGS.apiURL}/user/changepass`, passwordArray, { headers: this.authService.authHeader(), responseType: 'text' }); + return this.http.put(`${Configuration.settings.apiURL}/user/changepass`, passwordArray, { headers: this.authService.authHeader(), responseType: 'text' }); } deleteUser(): any { - return this.http.delete(`${API_SETTINGS.apiURL}/user/deleteprofile`, { headers: this.authService.authHeader() }); + return this.http.delete(`${Configuration.settings.apiURL}/user/deleteprofile`, { headers: this.authService.authHeader() }); } } diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index f57441c0..c4f89ad8 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -1,4 +1,4 @@ -import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; +import { NgModule, CUSTOM_ELEMENTS_SCHEMA, APP_INITIALIZER } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms'; import { AppRoutingModule } from './app-routing.module'; @@ -47,7 +47,11 @@ import { GraphComponent } from './_elements/graph/graph.component'; import { TrainingComponent } from './training/training.component'; import { ItemExperimentComponent } from './_elements/item-experiment/item-experiment.component'; import { YesNoDialogComponent } from './_modals/yes-no-dialog/yes-no-dialog.component'; +import { Configuration } from './configuration.service'; +export function initializeApp(appConfig: Configuration) { + return () => appConfig.load(); +} @NgModule({ declarations: [ AppComponent, @@ -99,7 +103,14 @@ import { YesNoDialogComponent } from './_modals/yes-no-dialog/yes-no-dialog.comp NgChartsModule, Ng2SearchPipeModule, ], - providers: [], + providers: [ + Configuration, + { + provide: APP_INITIALIZER, + useFactory: initializeApp, + deps: [Configuration], multi: true + } + ], bootstrap: [AppComponent], schemas: [CUSTOM_ELEMENTS_SCHEMA], entryComponents: [AlertDialogComponent] diff --git a/frontend/src/app/configuration.service.spec.ts b/frontend/src/app/configuration.service.spec.ts new file mode 100644 index 00000000..ec51dfa5 --- /dev/null +++ b/frontend/src/app/configuration.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { ConfigurationService } from './configuration.service'; + +describe('ConfigurationService', () => { + let service: ConfigurationService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(ConfigurationService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/configuration.service.ts b/frontend/src/app/configuration.service.ts new file mode 100644 index 00000000..4d2b0987 --- /dev/null +++ b/frontend/src/app/configuration.service.ts @@ -0,0 +1,20 @@ +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { IConfig } from '../app/_data/IConfig' + +@Injectable() +export class Configuration { + static settings: IConfig; + constructor(private http: HttpClient) { } + load() { + const jsonFile = 'assets/config.json'; + return new Promise<void>((resolve, reject) => { + this.http.get(jsonFile).toPromise().then((response) => { + Configuration.settings = <IConfig>response; + resolve(); + }).catch((response: any) => { + reject(`Could not load file '${jsonFile}': ${JSON.stringify(response)}`); + }); + }); + } +}
\ No newline at end of file diff --git a/frontend/src/assets/config.json b/frontend/src/assets/config.json new file mode 100644 index 00000000..f6e9d621 --- /dev/null +++ b/frontend/src/assets/config.json @@ -0,0 +1,4 @@ +{ + "apiURL": "http://localhost:5283/api", + "apiWSUrl": "http://localhost:5283/chatHub" +}
\ No newline at end of file diff --git a/frontend/src/config.json b/frontend/src/config.json deleted file mode 100644 index f30f99bd..00000000 --- a/frontend/src/config.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "apiURL": "http://localhost:5283/api", - "apiWSUrl": "ws://localhost:5283/api/websocket/ws" -}
\ No newline at end of file diff --git a/production/app/config.json b/production/app/config.json deleted file mode 100644 index 0e0dcd23..00000000 --- a/production/app/config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - -}
\ No newline at end of file diff --git a/production/app/main.js b/production/app/main.js index 336f21fe..8a34b066 100644 --- a/production/app/main.js +++ b/production/app/main.js @@ -4,7 +4,7 @@ const path = require('path'); const app = express(); -const port = 8080; +const port = 10091; app.use(cors()); app.use(express.static(path.join(__dirname, './dist'))); |