fix: fix Docker dev proxy and handle non-JSON error responses in frontend
This commit is contained in:
@@ -63,3 +63,4 @@ services:
|
|||||||
- "5173:5173"
|
- "5173:5173"
|
||||||
environment:
|
environment:
|
||||||
NODE_ENV: development
|
NODE_ENV: development
|
||||||
|
API_URL: http://server:3000
|
||||||
|
|||||||
@@ -66,7 +66,13 @@ export async function apiFetch<T>(path: string, options: RequestInit = {}): Prom
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const json: ApiResponse<T> = await res.json();
|
const text = await res.text();
|
||||||
|
let json: ApiResponse<T>;
|
||||||
|
try {
|
||||||
|
json = JSON.parse(text);
|
||||||
|
} catch {
|
||||||
|
throw new Error(`Server error (${res.status})`);
|
||||||
|
}
|
||||||
if (!json.success) {
|
if (!json.success) {
|
||||||
throw new Error(json.error?.message || 'Request failed');
|
throw new Error(json.error?.message || 'Request failed');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export default defineConfig({
|
|||||||
server: {
|
server: {
|
||||||
port: 5173,
|
port: 5173,
|
||||||
proxy: {
|
proxy: {
|
||||||
'/api': 'http://localhost:3000',
|
'/api': process.env.API_URL || 'http://localhost:3000',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user