feat: support runtime base path configuration via BASE_PATH env var

This commit is contained in:
ZacharyZcR
2026-05-13 16:13:20 +08:00
parent ec87f8a4d1
commit 1727601fbe
3 changed files with 12 additions and 0 deletions
+6
View File
@@ -135,6 +135,12 @@ fi
echo "Starting nginx..." echo "Starting nginx..."
nginx -c /tmp/nginx/nginx.conf nginx -c /tmp/nginx/nginx.conf
# Inject runtime BASE_PATH into frontend if configured
if [ -n "$BASE_PATH" ]; then
echo "Injecting BASE_PATH: $BASE_PATH"
find /app/html -name "index.html" -exec sed -i "s|window.__TERMIX_BASE_PATH__ = \"\"|window.__TERMIX_BASE_PATH__ = \"$BASE_PATH\"|g" {} \;
fi
echo "Starting backend services..." echo "Starting backend services..."
cd /app cd /app
export NODE_ENV=production export NODE_ENV=production
+1
View File
@@ -47,6 +47,7 @@
</style> </style>
</head> </head>
<body> <body>
<script>window.__TERMIX_BASE_PATH__ = "";</script>
<div id="root"></div> <div id="root"></div>
<script type="module" src="/src/main.tsx"></script> <script type="module" src="/src/main.tsx"></script>
</body> </body>
+5
View File
@@ -1,4 +1,9 @@
export function getBasePath(): string { export function getBasePath(): string {
const runtime = (window as unknown as Record<string, unknown>)
.__TERMIX_BASE_PATH__ as string | undefined;
if (runtime) {
return runtime.endsWith("/") ? runtime.slice(0, -1) : runtime;
}
const base = import.meta.env.BASE_URL || "/"; const base = import.meta.env.BASE_URL || "/";
if (base === "./" || base === "/") return ""; if (base === "./" || base === "/") return "";
return base.endsWith("/") ? base.slice(0, -1) : base; return base.endsWith("/") ? base.slice(0, -1) : base;