From 23435c67f09dfb2377a05ca4c0f7f5f78e2e673d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Wed, 3 Nov 2021 12:23:44 +0100 Subject: [PATCH] FIX productive websocket url --- src/main/angular/src/app/api/api.service.ts | 16 ++++++++++------ .../src/environments/environment.prod.ts | 3 ++- .../angular/src/environments/environment.ts | 4 ++-- .../de/ph87/homeautomation/DemoDataService.java | 17 +++++++++++------ 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/main/angular/src/app/api/api.service.ts b/src/main/angular/src/app/api/api.service.ts index cd650c4..51fb3f9 100644 --- a/src/main/angular/src/app/api/api.service.ts +++ b/src/main/angular/src/app/api/api.service.ts @@ -33,7 +33,7 @@ export class ApiService { private http: HttpClient, ) { this.webSocketClient = Stomp.over(function () { - return new WebSocket(environment.apiBasePath.replace('http', 'ws') + "websocket"); + return new WebSocket(ApiService.url("ws", "websocket")); }); this.webSocketClient.debug = () => null; this.webSocketClient.connect({}, () => { @@ -46,23 +46,27 @@ export class ApiService { } getItem(path: string, fromJson: (json: any) => T, next: (item: T) => void = NO_OP, error: (error: any) => void = NO_OP) { - this.http.get(environment.apiBasePath + path).pipe(map(fromJson)).subscribe(next, errorInterceptor(error)); + this.http.get(ApiService.url("http", path)).pipe(map(fromJson)).subscribe(next, errorInterceptor(error)); } getList(path: string, fromJson: (json: any) => T, compare: (a: T, b: T) => number = NO_COMPARE, next: (list: T[]) => void = NO_OP, error: (error: any) => void = NO_OP) { - this.http.get(environment.apiBasePath + path).pipe(map(list => list.map(fromJson).sort(compare))).subscribe(next, errorInterceptor(error)); + this.http.get(ApiService.url("http", path)).pipe(map(list => list.map(fromJson).sort(compare))).subscribe(next, errorInterceptor(error)); } postReturnNone(path: string, data: any, next: (_: void) => void = NO_OP, error: (error: any) => void = NO_OP) { - this.http.post(environment.apiBasePath + path, data).subscribe(next, errorInterceptor(error)); + this.http.post(ApiService.url("http", path), data).subscribe(next, errorInterceptor(error)); } postReturnItem(path: string, data: any, fromJson: (json: any) => T, next: (item: T) => void = NO_OP, error: (error: any) => void = NO_OP) { - this.http.post(environment.apiBasePath + path, data).pipe(map(fromJson)).subscribe(next, errorInterceptor(error)); + this.http.post(ApiService.url("http", path), data).pipe(map(fromJson)).subscribe(next, errorInterceptor(error)); } postReturnList(path: string, data: any, fromJson: (json: any) => T, next: (list: T[]) => void = NO_OP, error: (error: any) => void = NO_OP) { - this.http.post(environment.apiBasePath + path, data).pipe(map(list => list.map(fromJson))).subscribe(next, errorInterceptor(error)); + this.http.post(ApiService.url("http", path), data).pipe(map(list => list.map(fromJson))).subscribe(next, errorInterceptor(error)); + } + + private static url(schema: string, path: string): string { + return schema + "://" + environment.host + ":" + environment.port + "/" + path; } } diff --git a/src/main/angular/src/environments/environment.prod.ts b/src/main/angular/src/environments/environment.prod.ts index 152f223..87d85a3 100644 --- a/src/main/angular/src/environments/environment.prod.ts +++ b/src/main/angular/src/environments/environment.prod.ts @@ -1,4 +1,5 @@ export const environment = { production: true, - apiBasePath: '/', + host: window.location.host.split(":")[0], + port: window.location.port, }; diff --git a/src/main/angular/src/environments/environment.ts b/src/main/angular/src/environments/environment.ts index d72c887..fa2442e 100644 --- a/src/main/angular/src/environments/environment.ts +++ b/src/main/angular/src/environments/environment.ts @@ -4,8 +4,8 @@ export const environment = { production: false, - apiBasePath: 'http://localhost:8080/', - // apiBasePath: 'http://10.0.0.50:8080/', + host: window.location.host.split(":")[0], + port: 8080, }; /* diff --git a/src/main/java/de/ph87/homeautomation/DemoDataService.java b/src/main/java/de/ph87/homeautomation/DemoDataService.java index bf36491..48dcbbe 100644 --- a/src/main/java/de/ph87/homeautomation/DemoDataService.java +++ b/src/main/java/de/ph87/homeautomation/DemoDataService.java @@ -1,6 +1,7 @@ package de.ph87.homeautomation; import com.luckycatlabs.sunrisesunset.Zenith; +import de.ph87.homeautomation.device.DeviceRepository; import de.ph87.homeautomation.device.DeviceWriteService; import de.ph87.homeautomation.device.devices.DeviceDto; import de.ph87.homeautomation.knx.group.KnxGroupDto; @@ -40,6 +41,8 @@ public class DemoDataService { private final DeviceWriteService deviceWriteService; + private final DeviceRepository deviceRepository; + @PostConstruct public void postConstruct() { final KnxGroupDto eg_flur_licht_schalten = createKnxGroupIfNotExists("EG Flur Licht Schalten", 0, 5, 14, "1.001", PropertyType.ON_OFF, false, false); @@ -64,12 +67,14 @@ public class DemoDataService { final KnxGroupDto helligkeit = createKnxGroupIfNotExists("Helligkeit", 0, 5, 6, "9.004", PropertyType.LUX, false, true); - createDeviceSwitch("Ambiente EG", ambiente_eg_status.getProperty(), ambiente_eg_schalten.getProperty()); - createDeviceSwitch("Ambiente OG", ambiente_og_status.getProperty(), ambiente_og_schalten.getProperty()); - createDeviceSwitch("Bad Licht", bad_licht_status.getProperty(), bad_licht_schalten.getProperty()); - createDeviceShutter("Wohnzimmer Rollladen", null, wohnzimmer_rollladen_position_anfahren.getProperty()); - createDeviceShutter("Schlafzimmer Rollladen", null, schlafzimmer_rollladen_position_anfahren.getProperty()); - createDeviceShutter("Flur Rollladen", null, flur_og_rollladen_position_anfahren.getProperty()); + if (deviceRepository.count() == 0) { + createDeviceSwitch("Ambiente EG", ambiente_eg_status.getProperty(), ambiente_eg_schalten.getProperty()); + createDeviceSwitch("Ambiente OG", ambiente_og_status.getProperty(), ambiente_og_schalten.getProperty()); + createDeviceSwitch("Bad Licht", bad_licht_status.getProperty(), bad_licht_schalten.getProperty()); + createDeviceShutter("Wohnzimmer Rollladen", null, wohnzimmer_rollladen_position_anfahren.getProperty()); + createDeviceShutter("Schlafzimmer Rollladen", null, schlafzimmer_rollladen_position_anfahren.getProperty()); + createDeviceShutter("Flur Rollladen", null, flur_og_rollladen_position_anfahren.getProperty()); + } if (scheduleRepository.count() == 0) { final Schedule scheduleEgFlurLicht = createSchedule(true, "EG Flur Licht", eg_flur_licht_schalten.getProperty());