Spaces:
Running
Running
add /api/products-index same-origin proxy (fix VAIX RAG CORS)
Browse files
index.ts
CHANGED
|
@@ -1193,6 +1193,19 @@ const server = Bun.serve({
|
|
| 1193 |
return new Response("proxy error: " + String(e?.message || e), { status: 502 });
|
| 1194 |
}
|
| 1195 |
}},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1196 |
"/api/img": { GET: async (req: Request) => {
|
| 1197 |
|
| 1198 |
|
|
|
|
| 1193 |
return new Response("proxy error: " + String(e?.message || e), { status: 502 });
|
| 1194 |
}
|
| 1195 |
}},
|
| 1196 |
+
"/api/products-index": { GET: async (req: Request) => {
|
| 1197 |
+
// Same-origin proxy for the full products_index.json (VAIX RAG engine),
|
| 1198 |
+
// avoiding CORS on the HF resolve->xethub redirect from the browser.
|
| 1199 |
+
try {
|
| 1200 |
+
const u = "https://huggingface.co/datasets/bep40/grob-products-updated/resolve/main/products_index.json";
|
| 1201 |
+
const resp = await fetch(u, { headers: { "User-Agent": "Mozilla/5.0 (compatible; VAI-Avatar2/1.0)" }, signal: AbortSignal.timeout(60000) });
|
| 1202 |
+
if (!resp.ok) return new Response("upstream " + resp.status, { status: 502 });
|
| 1203 |
+
const buf = Buffer.from(await resp.arrayBuffer());
|
| 1204 |
+
return new Response(buf, { headers: { "Content-Type": "application/json; charset=utf-8", "Cache-Control": "public, max-age=600", "Access-Control-Allow-Origin": "*" } });
|
| 1205 |
+
} catch (e: any) {
|
| 1206 |
+
return new Response("proxy error: " + String(e?.message || e), { status: 502 });
|
| 1207 |
+
}
|
| 1208 |
+
}},
|
| 1209 |
"/api/img": { GET: async (req: Request) => {
|
| 1210 |
|
| 1211 |
|