This commit is contained in:
Alex Holliday committed 2025-12-10 19:01:59 +00:00
1 parent 35679fb433
commit 8d3d764a0d
5 files changed
+41 -65

No files matched your search

+2 -1
View File
@@ -11,7 +11,8 @@
<body> <body>
<div id="root"></div> <div id="root"></div>
<script type="module" src="/env.js"></script>
<script type="module" src="/src/main.tsx"></script> <script type="module" src="/src/main.tsx"></script>
</body> </body>
</html> </html>
-34
View File
@@ -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;
# }
}
+33 -17
View File
@@ -1,5 +1,11 @@
import type { DeploymentMode } from "@/types/env"; import type { DeploymentMode } from "@/types/env";
declare global {
interface Window {
__ENV?: Record<string, unknown>;
}
}
export interface IEnvConfig { export interface IEnvConfig {
HOST: string; HOST: string;
GLOBAL_REFRESH: number; GLOBAL_REFRESH: number;
@@ -7,25 +13,35 @@ export interface IEnvConfig {
DEPLOYMENT_MODE: DeploymentMode; DEPLOYMENT_MODE: DeploymentMode;
} }
const rawRefresh = import.meta.env.VITE_APP_GLOBAL_REFRESH; const RT = (typeof window !== "undefined" && window.__ENV) || undefined;
const parsedRefresh = Number(rawRefresh);
const GLOBAL_REFRESH = Number.isFinite(parsedRefresh) ? parsedRefresh : 60000;
const rawMode = import.meta.env.VITE_APP_DEPLOYMENT_MODE as const requireKey = (key: string): string => {
| DeploymentMode if (!RT || !(key in RT)) {
| string throw new Error(`Missing runtime config: ${key}`);
| undefined; }
const normalizedMode = const value = RT[key];
typeof rawMode === "string" ? (rawMode as string).trim().toLowerCase() : undefined; if (value == null || String(value).trim() === "") {
const DEPLOYMENT_MODE: DeploymentMode = throw new Error(`Invalid runtime config: ${key}`);
normalizedMode === "saas" || normalizedMode === "self_hosted" }
? (normalizedMode as DeploymentMode) return String(value);
: "self_hosted"; };
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 = { export const config: IEnvConfig = {
HOST: import.meta.env.VITE_APP_HOST || "http://localhost:5173", HOST,
GLOBAL_REFRESH, GLOBAL_REFRESH: GLOBAL_REFRESH_NUM,
API_BASE_URL: API_BASE_URL,
import.meta.env.VITE_APP_API_BASE_URL || "http://localhost:52345/api/v1",
DEPLOYMENT_MODE, DEPLOYMENT_MODE,
}; };
+3 -11
View File
@@ -1,12 +1,4 @@
/// <reference types="vite/client" /> /// <reference types="vite/client" />
import type { DeploymentMode } from "@/types/env"; // Runtime config now provided via window.__ENV; import.meta.env keys are not used.
interface ImportMetaEnv { interface ImportMetaEnv {}
readonly VITE_APP_HOST?: string; interface ImportMeta { readonly env: ImportMetaEnv }
readonly VITE_APP_GLOBAL_REFRESH?: string;
readonly VITE_APP_API_BASE_URL?: string;
readonly VITE_APP_DEPLOYMENT_MODE?: DeploymentMode;
}
interface ImportMeta {
readonly env: ImportMetaEnv;
}
+3 -2
View File
@@ -1,10 +1,11 @@
import axios from "axios"; import axios from "axios";
import type { AxiosError } from "axios"; import type { AxiosError } from "axios";
import type { AxiosRequestConfig, AxiosResponse } 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({ const api = axios.create({
baseURL: BASE_URL || "http://localhost:55555/api/v2", baseURL: BASE_URL,
withCredentials: true, withCredentials: true,
}); });