From 227c6a2cd980fefc9e5d38871a6de413b7c9bf49 Mon Sep 17 00:00:00 2001 From: Akiff Manji Date: Wed, 9 Oct 2024 16:22:29 +0000 Subject: [PATCH] chore: parameterize URLs Signed-off-by: Akiff Manji --- .../tenant-ui/config/custom-environment-variables.json | 3 ++- services/tenant-ui/config/default.json | 3 ++- services/tenant-ui/frontend/src/store/logStore.ts | 7 +++++-- services/tenant-ui/src/routes/router.ts | 2 +- services/tenant-ui/src/services/log-stream.ts | 7 +++---- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/services/tenant-ui/config/custom-environment-variables.json b/services/tenant-ui/config/custom-environment-variables.json index 3c7ae398a..f4a686d84 100644 --- a/services/tenant-ui/config/custom-environment-variables.json +++ b/services/tenant-ui/config/custom-environment-variables.json @@ -46,6 +46,7 @@ }, "server": { "tractionUrl": "SERVER_TRACTION_URL", + "lokiUrl": "SERVER_LOKI_URL", "oidc": { "jwksUri": "SERVER_OIDC_JWKS", "realm": "SERVER_OIDC_REALM", @@ -65,4 +66,4 @@ "innkeeperInbox": "SERVER_SMTP_INNKEEPER_INBOX" } } -} +} \ No newline at end of file diff --git a/services/tenant-ui/config/default.json b/services/tenant-ui/config/default.json index 09c920a78..ce1bd8ad3 100644 --- a/services/tenant-ui/config/default.json +++ b/services/tenant-ui/config/default.json @@ -54,6 +54,7 @@ "port": "8080", "staticFiles": "../../frontend/dist", "tractionUrl": "http://localhost:5100", + "lokiUrl": "ws://localhost:3100", "oidc": { "jwksUri": "https://dev.loginproxy.gov.bc.ca/auth/realms/digitaltrust-citz/protocol/openid-connect/certs", "realm": "digitaltrust-citz", @@ -73,4 +74,4 @@ "innkeeperInbox": "lucas.o'neil@gov.bc.ca" } } -} +} \ No newline at end of file diff --git a/services/tenant-ui/frontend/src/store/logStore.ts b/services/tenant-ui/frontend/src/store/logStore.ts index b1018a953..04aeab9a1 100644 --- a/services/tenant-ui/frontend/src/store/logStore.ts +++ b/services/tenant-ui/frontend/src/store/logStore.ts @@ -1,6 +1,6 @@ import { defineStore } from 'pinia'; import { Ref, ref } from 'vue'; -import { useTokenStore } from './tokenStore'; +import { useConfigStore, useTokenStore } from '@/store'; export enum LogStreamState { OPEN, @@ -13,6 +13,7 @@ export enum LogOrder { } export const useLogStore = defineStore('log', () => { + const { config } = useConfigStore(); const { token } = useTokenStore(); const logStream: Ref = ref(null); @@ -41,7 +42,9 @@ export const useLogStore = defineStore('log', () => { throw new Error('No token available to start log stream'); } if (!logStream.value) { - logStream.value = new WebSocket('ws://localhost:8080?token=' + token); + logStream.value = new WebSocket( + `${config.server.lokiUrl}?token=${token}` + ); logStream.value.onopen = () => { logStreamState.value = LogStreamState.OPEN; }; diff --git a/services/tenant-ui/src/routes/router.ts b/services/tenant-ui/src/routes/router.ts index 443373d56..b165062c8 100644 --- a/services/tenant-ui/src/routes/router.ts +++ b/services/tenant-ui/src/routes/router.ts @@ -22,7 +22,7 @@ router.use(express.json()); // For the secured innkeepr OIDC login request to verify the token and get a token from Traction router.get( "/innkeeperLogin", - // @ts-ignore + // @ts-expect-error: secure function is not typed correctly secure(jwksService), async (req: any, res: Response, next: NextFunction) => { try { diff --git a/services/tenant-ui/src/services/log-stream.ts b/services/tenant-ui/src/services/log-stream.ts index 0fd06da4d..1de7a9a3d 100644 --- a/services/tenant-ui/src/services/log-stream.ts +++ b/services/tenant-ui/src/services/log-stream.ts @@ -4,9 +4,8 @@ import config from "config"; import jwt from "jsonwebtoken"; import WebSocket from "ws"; -const WEBSOCKET_URL = "ws://host.docker.internal:3100/loki/api/v1/tail"; -// const TRACTION_URL: string = config.get("server.tractionUrl"); -const TRACTION_URL = "http://host.docker.internal:8032"; +const LOKI_URL: string = config.get("server.lokiUrl"); +const TRACTION_URL: string = config.get("server.tractionUrl"); const wss = new WebSocket.Server({ noServer: true }); @@ -54,7 +53,7 @@ const logError = (err: Error) => { const handleLokiWebSocket = (tenantId: string, ws: WebSocket) => { const loki = new WebSocket( - `${WEBSOCKET_URL}?query={container_name="scripts-traction-agent-1"} |= \`${tenantId}\`` + `${LOKI_URL}/loki/api/v1/tail?query={container_name="scripts-traction-agent-1"} |= \`${tenantId}\`` ); loki.on("open", () => {