FIX productive websocket url

This commit is contained in:
Patrick Haßel 2021-11-03 12:23:44 +01:00
parent 6b58d896b4
commit 23435c67f0
4 changed files with 25 additions and 15 deletions

View File

@ -33,7 +33,7 @@ export class ApiService {
private http: HttpClient, private http: HttpClient,
) { ) {
this.webSocketClient = Stomp.over(function () { 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.debug = () => null;
this.webSocketClient.connect({}, () => { this.webSocketClient.connect({}, () => {
@ -46,23 +46,27 @@ export class ApiService {
} }
getItem<T>(path: string, fromJson: (json: any) => T, next: (item: T) => void = NO_OP, error: (error: any) => void = NO_OP) { getItem<T>(path: string, fromJson: (json: any) => T, next: (item: T) => void = NO_OP, error: (error: any) => void = NO_OP) {
this.http.get<any>(environment.apiBasePath + path).pipe(map(fromJson)).subscribe(next, errorInterceptor(error)); this.http.get<any>(ApiService.url("http", path)).pipe(map(fromJson)).subscribe(next, errorInterceptor(error));
} }
getList<T>(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) { getList<T>(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<any[]>(environment.apiBasePath + path).pipe(map(list => list.map(fromJson).sort(compare))).subscribe(next, errorInterceptor(error)); this.http.get<any[]>(ApiService.url("http", path)).pipe(map(list => list.map(fromJson).sort(compare))).subscribe(next, errorInterceptor(error));
} }
postReturnNone<T>(path: string, data: any, next: (_: void) => void = NO_OP, error: (error: any) => void = NO_OP) { postReturnNone<T>(path: string, data: any, next: (_: void) => void = NO_OP, error: (error: any) => void = NO_OP) {
this.http.post<any>(environment.apiBasePath + path, data).subscribe(next, errorInterceptor(error)); this.http.post<any>(ApiService.url("http", path), data).subscribe(next, errorInterceptor(error));
} }
postReturnItem<T>(path: string, data: any, fromJson: (json: any) => T, next: (item: T) => void = NO_OP, error: (error: any) => void = NO_OP) { postReturnItem<T>(path: string, data: any, fromJson: (json: any) => T, next: (item: T) => void = NO_OP, error: (error: any) => void = NO_OP) {
this.http.post<any>(environment.apiBasePath + path, data).pipe(map(fromJson)).subscribe(next, errorInterceptor(error)); this.http.post<any>(ApiService.url("http", path), data).pipe(map(fromJson)).subscribe(next, errorInterceptor(error));
} }
postReturnList<T>(path: string, data: any, fromJson: (json: any) => T, next: (list: T[]) => void = NO_OP, error: (error: any) => void = NO_OP) { postReturnList<T>(path: string, data: any, fromJson: (json: any) => T, next: (list: T[]) => void = NO_OP, error: (error: any) => void = NO_OP) {
this.http.post<any>(environment.apiBasePath + path, data).pipe(map(list => list.map(fromJson))).subscribe(next, errorInterceptor(error)); this.http.post<any>(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;
} }
} }

View File

@ -1,4 +1,5 @@
export const environment = { export const environment = {
production: true, production: true,
apiBasePath: '/', host: window.location.host.split(":")[0],
port: window.location.port,
}; };

View File

@ -4,8 +4,8 @@
export const environment = { export const environment = {
production: false, production: false,
apiBasePath: 'http://localhost:8080/', host: window.location.host.split(":")[0],
// apiBasePath: 'http://10.0.0.50:8080/', port: 8080,
}; };
/* /*

View File

@ -1,6 +1,7 @@
package de.ph87.homeautomation; package de.ph87.homeautomation;
import com.luckycatlabs.sunrisesunset.Zenith; import com.luckycatlabs.sunrisesunset.Zenith;
import de.ph87.homeautomation.device.DeviceRepository;
import de.ph87.homeautomation.device.DeviceWriteService; import de.ph87.homeautomation.device.DeviceWriteService;
import de.ph87.homeautomation.device.devices.DeviceDto; import de.ph87.homeautomation.device.devices.DeviceDto;
import de.ph87.homeautomation.knx.group.KnxGroupDto; import de.ph87.homeautomation.knx.group.KnxGroupDto;
@ -40,6 +41,8 @@ public class DemoDataService {
private final DeviceWriteService deviceWriteService; private final DeviceWriteService deviceWriteService;
private final DeviceRepository deviceRepository;
@PostConstruct @PostConstruct
public void 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); 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); final KnxGroupDto helligkeit = createKnxGroupIfNotExists("Helligkeit", 0, 5, 6, "9.004", PropertyType.LUX, false, true);
if (deviceRepository.count() == 0) {
createDeviceSwitch("Ambiente EG", ambiente_eg_status.getProperty(), ambiente_eg_schalten.getProperty()); createDeviceSwitch("Ambiente EG", ambiente_eg_status.getProperty(), ambiente_eg_schalten.getProperty());
createDeviceSwitch("Ambiente OG", ambiente_og_status.getProperty(), ambiente_og_schalten.getProperty()); createDeviceSwitch("Ambiente OG", ambiente_og_status.getProperty(), ambiente_og_schalten.getProperty());
createDeviceSwitch("Bad Licht", bad_licht_status.getProperty(), bad_licht_schalten.getProperty()); createDeviceSwitch("Bad Licht", bad_licht_status.getProperty(), bad_licht_schalten.getProperty());
createDeviceShutter("Wohnzimmer Rollladen", null, wohnzimmer_rollladen_position_anfahren.getProperty()); createDeviceShutter("Wohnzimmer Rollladen", null, wohnzimmer_rollladen_position_anfahren.getProperty());
createDeviceShutter("Schlafzimmer Rollladen", null, schlafzimmer_rollladen_position_anfahren.getProperty()); createDeviceShutter("Schlafzimmer Rollladen", null, schlafzimmer_rollladen_position_anfahren.getProperty());
createDeviceShutter("Flur Rollladen", null, flur_og_rollladen_position_anfahren.getProperty()); createDeviceShutter("Flur Rollladen", null, flur_og_rollladen_position_anfahren.getProperty());
}
if (scheduleRepository.count() == 0) { if (scheduleRepository.count() == 0) {
final Schedule scheduleEgFlurLicht = createSchedule(true, "EG Flur Licht", eg_flur_licht_schalten.getProperty()); final Schedule scheduleEgFlurLicht = createSchedule(true, "EG Flur Licht", eg_flur_licht_schalten.getProperty());