Spaces:
Sleeping
Sleeping
[KM-571] [DED][FE] Fix Deployment Interview Page
Browse files- server.js +12 -2
- src/env.ts +16 -0
- src/services/api.ts +3 -6
- src/services/interviewApi.ts +3 -2
server.js
CHANGED
|
@@ -25,8 +25,8 @@ const MIME = {
|
|
| 25 |
".webp": "image/webp",
|
| 26 |
};
|
| 27 |
|
| 28 |
-
console.log(`Starting server on port ${PORT}`);
|
| 29 |
-
console.log(`Backend URL: ${BACKEND_URL || "(not set)"}`);
|
| 30 |
|
| 31 |
const server = http.createServer((req, res) => {
|
| 32 |
const parsed = url.parse(req.url);
|
|
@@ -77,6 +77,16 @@ const server = http.createServer((req, res) => {
|
|
| 77 |
return;
|
| 78 |
}
|
| 79 |
const ext = path.extname(filePath).toLowerCase();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
res.writeHead(200, { "Content-Type": MIME[ext] || "application/octet-stream" });
|
| 81 |
res.end(data);
|
| 82 |
});
|
|
|
|
| 25 |
".webp": "image/webp",
|
| 26 |
};
|
| 27 |
|
| 28 |
+
// console.log(`Starting server on port ${PORT}`);
|
| 29 |
+
// console.log(`Backend URL: ${BACKEND_URL || "(not set)"}`);
|
| 30 |
|
| 31 |
const server = http.createServer((req, res) => {
|
| 32 |
const parsed = url.parse(req.url);
|
|
|
|
| 77 |
return;
|
| 78 |
}
|
| 79 |
const ext = path.extname(filePath).toLowerCase();
|
| 80 |
+
if (ext === ".html") {
|
| 81 |
+
const envScript = `<script>window.__ENV__ = ${JSON.stringify({
|
| 82 |
+
VITE_ORCHESTRATION_API_BASE_URL: process.env.VITE_ORCHESTRATION_API_BASE_URL || "",
|
| 83 |
+
VITE_AGENTIC_API_BASE_URL: process.env.VITE_AGENTIC_API_BASE_URL || "",
|
| 84 |
+
})};</script>`;
|
| 85 |
+
const modified = data.toString("utf8").replace("</head>", `${envScript}</head>`);
|
| 86 |
+
res.writeHead(200, { "Content-Type": "text/html" });
|
| 87 |
+
res.end(modified);
|
| 88 |
+
return;
|
| 89 |
+
}
|
| 90 |
res.writeHead(200, { "Content-Type": MIME[ext] || "application/octet-stream" });
|
| 91 |
res.end(data);
|
| 92 |
});
|
src/env.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare global {
|
| 2 |
+
interface Window {
|
| 3 |
+
__ENV__?: {
|
| 4 |
+
VITE_ORCHESTRATION_API_BASE_URL?: string;
|
| 5 |
+
VITE_AGENTIC_API_BASE_URL?: string;
|
| 6 |
+
};
|
| 7 |
+
}
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
export function getEnv(key: keyof NonNullable<Window["__ENV__"]>): string {
|
| 11 |
+
return (
|
| 12 |
+
window.__ENV__?.[key] ??
|
| 13 |
+
(import.meta as unknown as { env: Record<string, string> }).env[key] ??
|
| 14 |
+
""
|
| 15 |
+
);
|
| 16 |
+
}
|
src/services/api.ts
CHANGED
|
@@ -93,13 +93,10 @@ export interface DataCatalog {
|
|
| 93 |
|
| 94 |
// βββ Base Clients βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 95 |
|
| 96 |
-
|
| 97 |
-
((import.meta as unknown as { env: Record<string, string> }).env
|
| 98 |
-
.VITE_ORCHESTRATION_API_BASE_URL) ?? "";
|
| 99 |
|
| 100 |
-
const
|
| 101 |
-
|
| 102 |
-
.VITE_AGENTIC_API_BASE_URL) ?? "";
|
| 103 |
|
| 104 |
async function request<T>(baseUrl: string, path: string, options?: RequestInit): Promise<T> {
|
| 105 |
const res = await fetch(`${baseUrl}${path}`, {
|
|
|
|
| 93 |
|
| 94 |
// βββ Base Clients βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 95 |
|
| 96 |
+
import { getEnv } from "@/env";
|
|
|
|
|
|
|
| 97 |
|
| 98 |
+
const ORCHESTRATION_BASE_URL = getEnv("VITE_ORCHESTRATION_API_BASE_URL");
|
| 99 |
+
const AGENTIC_BASE_URL = getEnv("VITE_AGENTIC_API_BASE_URL");
|
|
|
|
| 100 |
|
| 101 |
async function request<T>(baseUrl: string, path: string, options?: RequestInit): Promise<T> {
|
| 102 |
const res = await fetch(`${baseUrl}${path}`, {
|
src/services/interviewApi.ts
CHANGED
|
@@ -66,9 +66,10 @@ export type AudioServerEvent =
|
|
| 66 |
|
| 67 |
// βββ Base Client ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 68 |
|
|
|
|
|
|
|
| 69 |
const INTERVIEW_BASE_URL =
|
| 70 |
-
(
|
| 71 |
-
.VITE_ORCHESTRATION_API_BASE_URL) ?? "http://localhost:8080";
|
| 72 |
|
| 73 |
async function request<T>(path: string, options?: RequestInit): Promise<T> {
|
| 74 |
const res = await fetch(`${INTERVIEW_BASE_URL}${path}`, {
|
|
|
|
| 66 |
|
| 67 |
// βββ Base Client ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 68 |
|
| 69 |
+
import { getEnv } from "@/env";
|
| 70 |
+
|
| 71 |
const INTERVIEW_BASE_URL =
|
| 72 |
+
getEnv("VITE_ORCHESTRATION_API_BASE_URL") || "http://localhost:8080";
|
|
|
|
| 73 |
|
| 74 |
async function request<T>(path: string, options?: RequestInit): Promise<T> {
|
| 75 |
const res = await fetch(`${INTERVIEW_BASE_URL}${path}`, {
|