Skip to content

Commit 9a25d04

Browse files
committed
Fix API server retrieval: fallback to environment variables if not found in the DOM
1 parent b4896bb commit 9a25d04

2 files changed

Lines changed: 31 additions & 25 deletions

File tree

app/auth/synthesis/page.tsx

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,28 @@ export default function SynthesisPage() {
2020
const textareaRef = useRef<HTMLTextAreaElement>(null);
2121

2222
// Initialize the multi-voice synthesis mutation
23-
const { mutate: generateMultiVoiceSynthesis, isPending: isSynthesisLoading } =
24-
useMutationPostTextToSpeechMultiVoice(
25-
(data) => {
26-
// On success
27-
setIsLoading(false);
28-
if (data && data.length > 0 && data[0].data) {
29-
setAudioData(data[0].data);
30-
} else {
31-
setError('No audio data received from synthesis');
32-
}
33-
},
34-
(error) => {
35-
// On error
36-
setIsLoading(false);
37-
console.error('Synthesis error:', error);
38-
setError('Failed to generate synthesis. Please try again.');
39-
},
40-
);
23+
const {
24+
mutate: generateMultiVoiceSynthesis,
25+
isPending: isSynthesisLoading,
26+
data,
27+
} = useMutationPostTextToSpeechMultiVoice(
28+
(data) => {
29+
// On success
30+
setIsLoading(false);
31+
if (data && data.data && data.data.length) {
32+
setAudioData(data.data);
33+
setError(null);
34+
} else {
35+
setError('No audio data received from synthesis');
36+
}
37+
},
38+
(error) => {
39+
// On error
40+
setIsLoading(false);
41+
console.error('Synthesis error:', error);
42+
setError('Failed to generate synthesis. Please try again.');
43+
},
44+
);
4145

4246
const handleGenerate = async () => {
4347
if (!inputText.trim()) {

src/helpers.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ export function s3RandomPublicKey() {
3939
}
4040

4141
export function getApiServer() {
42-
const apiServer = document.querySelector("[data-store='apiServer']")
43-
?.textContent;
42+
const apiServer =
43+
document.querySelector("[data-store='apiServer']")?.textContent ||
44+
process.env.NEXT_PUBLIC_API_SERVER;
4445

4546
if (!apiServer) {
4647
throw new Error('apiServer not found');
@@ -50,8 +51,9 @@ export function getApiServer() {
5051
}
5152

5253
export function getBatchServer() {
53-
const batchServer = document.querySelector("[data-store='batchApiServer']")
54-
?.textContent;
54+
const batchServer =
55+
document.querySelector("[data-store='batchApiServer']")?.textContent ||
56+
process.env.NEXT_PUBLIC_BATCH_API_SERVER;
5557

5658
if (!batchServer) {
5759
throw new Error('batchServer not found');
@@ -62,9 +64,9 @@ export function getBatchServer() {
6264

6365
// generate a function getImageGenerationServer
6466
export function getImageGenerationServer() {
65-
const imageGenerationServer = document.querySelector(
66-
"[data-store='imageGenerationServer']",
67-
)?.textContent;
67+
const imageGenerationServer =
68+
document.querySelector("[data-store='imageGenerationServer']")
69+
?.textContent || process.env.NEXT_PUBLIC_IMAGE_GENERATION_SERVER_URL;
6870

6971
if (!imageGenerationServer) {
7072
throw new Error('imageGenerationServer not found');

0 commit comments

Comments
 (0)