File size: 800 Bytes
3bd432c
b8da9d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const BACKEND = 'https://fredyhoundayi-quick.hf.space';

/**
 * Proxy a request to the FastAPI backend.
 * @param {string} path - Backend path (e.g. "/build")
 * @param {RequestInit} options - Fetch options (method, headers, body)
 * @returns {Promise<Response>}
 */
export async function proxyRequest(path, options = {}) {
  const url = `${BACKEND}${path}`;
  try {
    const res = await fetch(url, options);
    const body = await res.text();
    return new Response(body, {
      status: res.status,
      headers: { 'Content-Type': res.headers.get('Content-Type') || 'application/json' },
    });
  } catch (err) {
    return new Response(JSON.stringify({ detail: `Backend unreachable: ${err.message}` }), {
      status: 503,
      headers: { 'Content-Type': 'application/json' },
    });
  }
}