From 6f55d8a6c93fc6918af9e5a20a715d1e9f9abab4 Mon Sep 17 00:00:00 2001 From: Alex Christoffer Rasmussen Date: Wed, 12 Nov 2025 19:28:29 +0800 Subject: [PATCH] use data in `` componenet to mark ontime cloud status (#1872) --- apps/client/src/common/utils/__tests__/linkUtils.test.ts | 7 +++++++ apps/client/src/externals.ts | 2 +- apps/server/src/externals.ts | 3 ++- package.json | 4 ++-- turbo.json | 2 +- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/client/src/common/utils/__tests__/linkUtils.test.ts b/apps/client/src/common/utils/__tests__/linkUtils.test.ts index 8716acdd2..32173dfd5 100644 --- a/apps/client/src/common/utils/__tests__/linkUtils.test.ts +++ b/apps/client/src/common/utils/__tests__/linkUtils.test.ts @@ -14,4 +14,11 @@ describe('linkToOTherHost', () => { const destination = linkToOtherHost('cloud.getontime.no', 'path', serverUrl, baseUri); expect(destination).toBe('https://cloud.getontime.no/user-hash/path'); }); + + it('should handle ontime app links', () => { + const serverUrl = 'https://app.getontime.no/user-hash'; + const baseUri = 'user-hash'; + const destination = linkToOtherHost('app.getontime.no', 'path', serverUrl, baseUri); + expect(destination).toBe('https://app.getontime.no/user-hash/path'); + }); }); diff --git a/apps/client/src/externals.ts b/apps/client/src/externals.ts index d7f572489..2cc5c1549 100644 --- a/apps/client/src/externals.ts +++ b/apps/client/src/externals.ts @@ -22,7 +22,7 @@ export const isProduction = import.meta.env.PROD; export const isDev = import.meta.env.DEV; export const currentHostName = window.location.hostname; export const isLocalhost = currentHostName === 'localhost' || currentHostName === '127.0.0.1'; -export const isOntimeCloud = currentHostName.includes('cloud.getontime.no'); +export const isOntimeCloud = document.querySelector('base')?.hasAttribute('data-is-cloud') // resolve entrypoint URLs diff --git a/apps/server/src/externals.ts b/apps/server/src/externals.ts index b90054512..24c40ec1d 100644 --- a/apps/server/src/externals.ts +++ b/apps/server/src/externals.ts @@ -5,6 +5,7 @@ import { readFileSync, writeFileSync } from 'node:fs'; import { srcFiles } from './setup/index.js'; +import { isOntimeCloud } from './setup/environment.js'; // ================================================= export const password = process.env.SESSION_PASSWORD; @@ -23,7 +24,7 @@ export function updateRouterPrefix(prefix: string | undefined = routerPrefix): s try { const data = readFileSync(srcFiles.clientIndexHtml, { encoding: 'utf-8', flag: 'r' }).replace( '', - ``, + ``, ); writeFileSync(srcFiles.clientIndexHtml, data, { encoding: 'utf-8', flag: 'w' }); } catch (_error) { diff --git a/package.json b/package.json index ac1a1ffa9..de7d7c77f 100644 --- a/package.json +++ b/package.json @@ -22,13 +22,13 @@ "type": "module", "scripts": { "dev": "turbo run dev", - "dev:prefix": "cross-env ROUTER_PREFIX=test turbo run dev --filter=ontime-server", + "dev:prefix": "cross-env ROUTER_PREFIX=test cross-env IS_CLOUD=True turbo run dev --filter=ontime-server", "dev:electron": "turbo run dev:electron", "lint": "turbo run lint", "typecheck": "turbo run typecheck", "build": "turbo run build", "build:docker": "cross-env NODE_ENV=docker turbo run build --filter=ontime-server --filter=ontime-ui", - "build:resolver": "cross-env turbo run build --filter=@getontime/resolver", + "build:resolver": "turbo run build --filter=@getontime/resolver", "dist-win": "turbo run dist-win", "dist-mac": "turbo run dist-mac", "dist-linux": "turbo run dist-linux", diff --git a/turbo.json b/turbo.json index a461bf556..0c729ad2a 100644 --- a/turbo.json +++ b/turbo.json @@ -14,7 +14,7 @@ "dev": { "cache": false, "persistent": true, - "env": ["ROUTER_PREFIX"] + "env": ["ROUTER_PREFIX", "IS_CLOUD"] }, "dev:electron": { "cache": false,