fix: relax proxy CORS restrictions and proxy all image streams to bypass camera CORS policies

This commit is contained in:
Antigravity AI committed 2026-05-10 19:44:20 +12:00
1 parent 6adb693f53
commit 2e30a04ff1
3 files changed
+24 -12

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "worldwideview",
"version": "2.5.4",
"version": "2.5.5",
"private": true,
"type": "module",
"packageManager": "[email protected]",
+18
View File
@@ -68,12 +68,16 @@ export async function GET(req: NextRequest) {
return NextResponse.json({ error: "Missing 'url' parameter" }, { status: 400 });
}
// By user request: We are no longer strict about CORS/SSRF.
// Allow any camera to work, including local network cameras.
/*
if (await isPrivateUrl(targetUrl)) {
return NextResponse.json(
{ error: "Requests to private/internal networks are not allowed" },
{ status: 403 },
);
}
*/
try {
const upstream = await fetch(targetUrl, {
@@ -104,6 +108,8 @@ export async function GET(req: NextRequest) {
"Content-Type": contentType,
"Cache-Control": "no-store",
"X-Content-Type-Options": "nosniff",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, OPTIONS",
},
});
} catch (error: unknown) {
@@ -115,3 +121,15 @@ export async function GET(req: NextRequest) {
);
}
}
export async function OPTIONS() {
return new Response(null, {
status: 204,
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Max-Age": "86400",
},
});
}
+5 -11
View File
@@ -63,20 +63,14 @@ export function getYouTubeEmbedUrl(url: string): string {
}
/**
* If the page is served over HTTPS and the stream is plain HTTP, rewrite
* the URL to go through our server-side stream proxy to avoid mixed-content
* blocks. Returns the original URL if no proxying is needed.
* Proxy stream URLs through our server-side proxy to avoid mixed-content blocks
* and bypass restrictive CORS policies from camera providers.
*/
export function getProxiedStreamUrl(url: string): string {
if (!url) return url;
const isHttpStream = url.startsWith("http://");
const pageIsHttps =
typeof window !== "undefined" && window.location.protocol === "https:";
if (isHttpStream && pageIsHttps) {
return `/api/camera/proxy/stream?url=${encodeURIComponent(url)}`;
}
return url;
// Always proxy to bypass CORS restrictions from camera providers!
return `/api/camera/proxy/stream?url=${encodeURIComponent(url)}`;
}
/** Return a user-friendly error message for a failed stream URL. */