From db7e4ec1a0eef8e178de5006b85de4e89acccdd1 Mon Sep 17 00:00:00 2001 From: Simon Hanna Date: Mon, 27 Aug 2018 23:01:02 +0200 Subject: [PATCH] Get the remote api port from the url --- src/app/openlp.service.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/app/openlp.service.ts b/src/app/openlp.service.ts index deedcf2..ab08d40 100644 --- a/src/app/openlp.service.ts +++ b/src/app/openlp.service.ts @@ -2,10 +2,10 @@ import { Injectable, EventEmitter } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { URLSearchParams, Http } from '@angular/http'; - import { Observable } from 'rxjs'; import { map, take } from 'rxjs/operators'; import { PluginDescription, State, Slide, ServiceItem } from './responses'; +import { environment } from '../environments/environment'; let deserialize = (json, cls) => { var inst = new cls(); @@ -20,11 +20,19 @@ let deserialize = (json, cls) => { @Injectable() export class OpenLPService { - private apiURL: string = 'http://localhost:4316'; + private apiURL: string; public stateChanged$: EventEmitter; constructor(private http: HttpClient) { + let port: string; + if (environment.production) { + port = window.location.port; + } else { + port = '4316'; + } + this.apiURL = `http://localhost:${port}`; + this.stateChanged$ = new EventEmitter(); let state:State = null; let ws:WebSocket = new WebSocket('ws://localhost:4317/state')