diff --git a/client/index.html b/client/index.html index ab7c560cd..f9f05c932 100644 --- a/client/index.html +++ b/client/index.html @@ -11,7 +11,8 @@
+ - \ No newline at end of file + diff --git a/client/nginx/conf.d/default.conf b/client/nginx/conf.d/default.conf deleted file mode 100644 index c3f993a08..000000000 --- a/client/nginx/conf.d/default.conf +++ /dev/null @@ -1,34 +0,0 @@ -server { - listen 80 default_server; - - server_name localhost; # Set server name to localhost - server_tokens off; - - location / { - root /usr/share/nginx/html; - index index.html index.htm; - try_files $uri $uri/ /index.html; - } - - # location /api/ { - # proxy_pass http://server:52345/api/; - # proxy_http_version 1.1; - # proxy_set_header Host $host; - # proxy_set_header X-Real-IP $remote_addr; - # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - # proxy_set_header X-Forwarded-Proto $scheme; - # proxy_set_header Connection ''; - # chunked_transfer_encoding off; - # proxy_buffering off; - # proxy_cache off; - # } - - # location /api-docs/ { - # proxy_pass http://server:52345/api-docs/; - # proxy_http_version 1.1; - # proxy_set_header Host $host; - # proxy_set_header X-Real-IP $remote_addr; - # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - # proxy_set_header X-Forwarded-Proto $scheme; - # } -} \ No newline at end of file diff --git a/client/src/config/index.ts b/client/src/config/index.ts index 9f0e106c4..7e497c0a7 100644 --- a/client/src/config/index.ts +++ b/client/src/config/index.ts @@ -1,5 +1,11 @@ import type { DeploymentMode } from "@/types/env"; +declare global { + interface Window { + __ENV?: Record; + } +} + export interface IEnvConfig { HOST: string; GLOBAL_REFRESH: number; @@ -7,25 +13,35 @@ export interface IEnvConfig { DEPLOYMENT_MODE: DeploymentMode; } -const rawRefresh = import.meta.env.VITE_APP_GLOBAL_REFRESH; -const parsedRefresh = Number(rawRefresh); -const GLOBAL_REFRESH = Number.isFinite(parsedRefresh) ? parsedRefresh : 60000; +const RT = (typeof window !== "undefined" && window.__ENV) || undefined; -const rawMode = import.meta.env.VITE_APP_DEPLOYMENT_MODE as - | DeploymentMode - | string - | undefined; -const normalizedMode = - typeof rawMode === "string" ? (rawMode as string).trim().toLowerCase() : undefined; -const DEPLOYMENT_MODE: DeploymentMode = - normalizedMode === "saas" || normalizedMode === "self_hosted" - ? (normalizedMode as DeploymentMode) - : "self_hosted"; +const requireKey = (key: string): string => { + if (!RT || !(key in RT)) { + throw new Error(`Missing runtime config: ${key}`); + } + const value = RT[key]; + if (value == null || String(value).trim() === "") { + throw new Error(`Invalid runtime config: ${key}`); + } + return String(value); +}; + +const HOST = requireKey("APP_HOST"); +const API_BASE_URL = requireKey("APP_API_BASE_URL"); +const GLOBAL_REFRESH_STR = requireKey("GLOBAL_REFRESH"); +const GLOBAL_REFRESH_NUM = Number(GLOBAL_REFRESH_STR); +if (!Number.isFinite(GLOBAL_REFRESH_NUM)) { + throw new Error(`GLOBAL_REFRESH must be a number, received: ${GLOBAL_REFRESH_STR}`); +} +const DEPLOYMENT_MODE_STR = requireKey("APP_DEPLOYMENT_MODE").toLowerCase(); +if (DEPLOYMENT_MODE_STR !== "saas" && DEPLOYMENT_MODE_STR !== "self_hosted") { + throw new Error(`APP_DEPLOYMENT_MODE must be 'saas' or 'self_hosted', received: ${DEPLOYMENT_MODE_STR}`); +} +const DEPLOYMENT_MODE = DEPLOYMENT_MODE_STR as DeploymentMode; export const config: IEnvConfig = { - HOST: import.meta.env.VITE_APP_HOST || "http://localhost:5173", - GLOBAL_REFRESH, - API_BASE_URL: - import.meta.env.VITE_APP_API_BASE_URL || "http://localhost:52345/api/v1", + HOST, + GLOBAL_REFRESH: GLOBAL_REFRESH_NUM, + API_BASE_URL, DEPLOYMENT_MODE, }; diff --git a/client/src/env.d.ts b/client/src/env.d.ts index 717f8accd..402de40f5 100644 --- a/client/src/env.d.ts +++ b/client/src/env.d.ts @@ -1,12 +1,4 @@ /// -import type { DeploymentMode } from "@/types/env"; -interface ImportMetaEnv { - readonly VITE_APP_HOST?: string; - readonly VITE_APP_GLOBAL_REFRESH?: string; - readonly VITE_APP_API_BASE_URL?: string; - readonly VITE_APP_DEPLOYMENT_MODE?: DeploymentMode; -} - -interface ImportMeta { - readonly env: ImportMetaEnv; -} +// Runtime config now provided via window.__ENV; import.meta.env keys are not used. +interface ImportMetaEnv {} +interface ImportMeta { readonly env: ImportMetaEnv } diff --git a/client/src/utils/ApiClient.ts b/client/src/utils/ApiClient.ts index eca9554d6..25f612772 100644 --- a/client/src/utils/ApiClient.ts +++ b/client/src/utils/ApiClient.ts @@ -1,10 +1,11 @@ import axios from "axios"; import type { AxiosError } from "axios"; import type { AxiosRequestConfig, AxiosResponse } from "axios"; -const BASE_URL = import.meta.env.VITE_APP_API_BASE_URL; +import { config } from "@/config"; +const BASE_URL = config.API_BASE_URL; const api = axios.create({ - baseURL: BASE_URL || "http://localhost:55555/api/v2", + baseURL: BASE_URL, withCredentials: true, });