ishaq101 commited on
Commit
017da10
·
1 Parent(s): 6078ab4

update server.js

Browse files
server.js CHANGED
@@ -77,6 +77,18 @@ 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
  });
 
77
  return;
78
  }
79
  const ext = path.extname(filePath).toLowerCase();
80
+
81
+ if (ext === ".html") {
82
+ const config = { VOICE_API_URL: process.env.VITE_API_BASE_VOICE_URL || "" };
83
+ const html = data.toString().replace(
84
+ "</head>",
85
+ `<script>window.__APP_CONFIG__=${JSON.stringify(config)};</script></head>`
86
+ );
87
+ res.writeHead(200, { "Content-Type": "text/html" });
88
+ res.end(html);
89
+ return;
90
+ }
91
+
92
  res.writeHead(200, { "Content-Type": MIME[ext] || "application/octet-stream" });
93
  res.end(data);
94
  });
src/hooks/useVoiceSession.ts CHANGED
@@ -40,8 +40,12 @@ const BUFFER_SOUNDS = [
40
  const RECORDER_SAMPLE_RATE = 16000;
41
 
42
  function getVoiceHttpBaseUrl(): string {
43
- return (import.meta as unknown as { env: Record<string, string> }).env
44
- .VITE_API_BASE_VOICE_URL ?? "http://localhost:7861";
 
 
 
 
45
  }
46
 
47
  export function useVoiceSession(opts: UseVoiceSessionOptions): UseVoiceSessionReturn {
 
40
  const RECORDER_SAMPLE_RATE = 16000;
41
 
42
  function getVoiceHttpBaseUrl(): string {
43
+ const w = window as unknown as { __APP_CONFIG__?: { VOICE_API_URL?: string } };
44
+ return (
45
+ w.__APP_CONFIG__?.VOICE_API_URL ||
46
+ (import.meta as unknown as { env: Record<string, string> }).env.VITE_API_BASE_VOICE_URL ||
47
+ "http://localhost:7861"
48
+ );
49
  }
50
 
51
  export function useVoiceSession(opts: UseVoiceSessionOptions): UseVoiceSessionReturn {
src/services/voiceApi.ts CHANGED
@@ -1,6 +1,12 @@
1
- const VOICE_BASE_URL =
2
- (import.meta as unknown as { env: Record<string, string> }).env
3
- .VITE_API_BASE_VOICE_URL ?? "http://localhost:7861";
 
 
 
 
 
 
4
 
5
  function writeString(view: DataView, offset: number, str: string): void {
6
  for (let i = 0; i < str.length; i++) view.setUint8(offset + i, str.charCodeAt(i));
 
1
+ function getVoiceBaseUrl(): string {
2
+ const w = window as unknown as { __APP_CONFIG__?: { VOICE_API_URL?: string } };
3
+ return (
4
+ w.__APP_CONFIG__?.VOICE_API_URL ||
5
+ (import.meta as unknown as { env: Record<string, string> }).env.VITE_API_BASE_VOICE_URL ||
6
+ "http://localhost:7861"
7
+ );
8
+ }
9
+ const VOICE_BASE_URL = getVoiceBaseUrl();
10
 
11
  function writeString(view: DataView, offset: number, str: string): void {
12
  for (let i = 0; i < str.length; i++) view.setUint8(offset + i, str.charCodeAt(i));