From 08d96a1b767d19644ef6d88c9934b46ec93f0c10 Mon Sep 17 00:00:00 2001 From: jonaswinkler Date: Tue, 2 Feb 2021 16:22:36 +0100 Subject: [PATCH] configure websocket endpoint for production --- src-ui/src/app/services/consumer-status.service.ts | 14 ++++++++------ src-ui/src/environments/environment.prod.ts | 4 +++- src-ui/src/environments/environment.ts | 3 ++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src-ui/src/app/services/consumer-status.service.ts b/src-ui/src/app/services/consumer-status.service.ts index 9c7d0417a..38f29a528 100644 --- a/src-ui/src/app/services/consumer-status.service.ts +++ b/src-ui/src/app/services/consumer-status.service.ts @@ -1,5 +1,6 @@ import { Injectable } from '@angular/core'; import { Subject } from 'rxjs'; +import { environment } from 'src/environments/environment'; import { WebsocketConsumerStatusMessage } from '../data/websocket-consumer-status-message'; export enum FileStatusPhase { @@ -77,7 +78,7 @@ export class ConsumerStatusService { constructor() { } - private statusWebSocked: WebSocket + private statusWebSocket: WebSocket private consumerStatus: FileStatus[] = [] @@ -123,8 +124,9 @@ export class ConsumerStatusService { connect() { this.disconnect() - this.statusWebSocked = new WebSocket("ws://localhost:8000/ws/status/"); - this.statusWebSocked.onmessage = (ev) => { + + this.statusWebSocket = new WebSocket(`${environment.webSocketProtocol}//${environment.webSocketHost}/ws/status/`); + this.statusWebSocket.onmessage = (ev) => { let statusMessage: WebsocketConsumerStatusMessage = JSON.parse(ev['data']) let statusMessageGet = this.get(statusMessage.task_id, statusMessage.filename) @@ -160,9 +162,9 @@ export class ConsumerStatusService { } disconnect() { - if (this.statusWebSocked) { - this.statusWebSocked.close() - this.statusWebSocked = null + if (this.statusWebSocket) { + this.statusWebSocket.close() + this.statusWebSocket = null } } diff --git a/src-ui/src/environments/environment.prod.ts b/src-ui/src/environments/environment.prod.ts index e8e801a83..4e38813b5 100644 --- a/src-ui/src/environments/environment.prod.ts +++ b/src-ui/src/environments/environment.prod.ts @@ -2,5 +2,7 @@ export const environment = { production: true, apiBaseUrl: "/api/", appTitle: "Paperless-ng", - version: "1.1.0" + version: "1.1.0", + webSocketHost: window.location.host, + webSocketProtocol: (window.location.protocol == "https:" ? "wss:" : "ws:") }; diff --git a/src-ui/src/environments/environment.ts b/src-ui/src/environments/environment.ts index 29dcb7ba1..b2c40e261 100644 --- a/src-ui/src/environments/environment.ts +++ b/src-ui/src/environments/environment.ts @@ -7,7 +7,8 @@ export const environment = { apiBaseUrl: "http://localhost:8000/api/", appTitle: "Paperless-ng", version: "DEVELOPMENT", - wsBaseUrl: "ws://localhost:8000/ws/" + webSocketHost: "localhost:8000", + webSocketProtocol: "ws:" }; /*