Files
web2app/worker/src/index.ts
shumengya f8b05c69d6 fix(android): allow network requests and relax WebView CSP
Enable cleartext HTTP in release APK, add network security config, and set connect-src CSP. Add CORS on Worker API for cross-origin fetches from packaged apps.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-06 13:53:05 +08:00

27 lines
683 B
TypeScript

import type { Env } from "./env";
import { handleBuildsRequest } from "./routes/builds";
import {
corsPreflightResponse,
jsonResponseWithCors,
} from "./lib/response";
export default {
async fetch(request: Request, env: Env): Promise<Response> {
const url = new URL(request.url);
if (request.method === "OPTIONS" && url.pathname.startsWith("/api/")) {
return corsPreflightResponse(request);
}
if (url.pathname === "/api/health") {
return jsonResponseWithCors(request, { ok: true });
}
if (url.pathname.startsWith("/api/builds")) {
return handleBuildsRequest(request, env, url);
}
return env.ASSETS.fetch(request);
},
};