ishaq101 commited on
Commit
ee46b9f
Β·
1 Parent(s): 475d02c

[KM-571] [DED][FE] Fix Deployment Interview Page

Browse files
Files changed (4) hide show
  1. server.js +12 -2
  2. src/env.ts +16 -0
  3. src/services/api.ts +3 -6
  4. 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
- const ORCHESTRATION_BASE_URL =
97
- ((import.meta as unknown as { env: Record<string, string> }).env
98
- .VITE_ORCHESTRATION_API_BASE_URL) ?? "";
99
 
100
- const AGENTIC_BASE_URL =
101
- ((import.meta as unknown as { env: Record<string, string> }).env
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
- ((import.meta as unknown as { env: Record<string, string> }).env
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}`, {