Spaces:
Sleeping
Sleeping
Lê Phi Nam commited on
Commit ·
68af9ee
1
Parent(s): 3a9c68b
Fix API URL: use bun script for reliable placeholder replacement
Browse files- Dockerfile +28 -8
Dockerfile
CHANGED
|
@@ -14,15 +14,35 @@ RUN bun install --frozen-lockfile
|
|
| 14 |
# Build static files (output lands in /app/frontend/dist)
|
| 15 |
COPY frontend/ ./frontend/
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
#
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
RUN VITE_API_URL="__OMNIVOICE_RUNTIME_ORIGIN__" bun run --cwd frontend build && \
|
| 24 |
-
|
| 25 |
-
sed -i 's|"__OMNIVOICE_RUNTIME_ORIGIN__"|window.location.origin|g' {} +
|
| 26 |
|
| 27 |
# ==========================================
|
| 28 |
# Runtime Stage: Python & PyTorch Backend
|
|
|
|
| 14 |
# Build static files (output lands in /app/frontend/dist)
|
| 15 |
COPY frontend/ ./frontend/
|
| 16 |
|
| 17 |
+
# Write a patcher script that replaces the API URL placeholder with
|
| 18 |
+
# window.location.origin in the compiled JS output. Using bun to run
|
| 19 |
+
# the script ensures it works on Alpine (no sed/find compatibility issues).
|
| 20 |
+
RUN cat > /tmp/patch_api.mjs << 'PATCHEOF'
|
| 21 |
+
import { readdirSync, statSync, readFileSync, writeFileSync } from "fs";
|
| 22 |
+
import { join } from "path";
|
| 23 |
+
|
| 24 |
+
function walk(dir) {
|
| 25 |
+
for (const f of readdirSync(dir)) {
|
| 26 |
+
const p = join(dir, f);
|
| 27 |
+
if (statSync(p).isDirectory()) walk(p);
|
| 28 |
+
else if (f.endsWith(".js")) {
|
| 29 |
+
let c = readFileSync(p, "utf8");
|
| 30 |
+
if (c.includes("__OMNIVOICE_RUNTIME_ORIGIN__")) {
|
| 31 |
+
c = c.replaceAll('"__OMNIVOICE_RUNTIME_ORIGIN__"', "window.location.origin");
|
| 32 |
+
c = c.replaceAll("'__OMNIVOICE_RUNTIME_ORIGIN__'", "window.location.origin");
|
| 33 |
+
c = c.replaceAll("__OMNIVOICE_RUNTIME_ORIGIN__", "window.location.origin");
|
| 34 |
+
writeFileSync(p, c);
|
| 35 |
+
console.log("Patched:", p);
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
walk("/app/frontend/dist");
|
| 41 |
+
PATCHEOF
|
| 42 |
+
|
| 43 |
+
# Build with placeholder, then patch compiled JS to use window.location.origin
|
| 44 |
RUN VITE_API_URL="__OMNIVOICE_RUNTIME_ORIGIN__" bun run --cwd frontend build && \
|
| 45 |
+
bun /tmp/patch_api.mjs
|
|
|
|
| 46 |
|
| 47 |
# ==========================================
|
| 48 |
# Runtime Stage: Python & PyTorch Backend
|