From 443ff77be95e778f16d2313dd131f504cdc67d52 Mon Sep 17 00:00:00 2001 From: MythEclipse Date: Fri, 8 May 2026 18:58:50 +0700 Subject: [PATCH] ci: add CF Workers deploy workflow + fix relay header forwarding --- .github/workflows/deploy.yml | 31 +++++++++++++++++++++ src/lib/relay-utils.ts | 52 ++++-------------------------------- 2 files changed, 36 insertions(+), 47 deletions(-) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..7d1cbdd --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,31 @@ +name: Deploy to Cloudflare Workers + +on: + push: + branches: [main, master] + workflow_dispatch: + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: oven-sh/setup-bun@v2 + with: + bun-version: latest + + - name: Install dependencies + run: bun install + working-directory: proxy-bun + + - name: Build worker + run: bun run build:worker + working-directory: proxy-bun + + - name: Deploy to Cloudflare + run: bunx wrangler deploy + working-directory: proxy-bun + env: + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} diff --git a/src/lib/relay-utils.ts b/src/lib/relay-utils.ts index d62e405..a5830a4 100644 --- a/src/lib/relay-utils.ts +++ b/src/lib/relay-utils.ts @@ -1,35 +1,7 @@ -export const ALLOWED_HEADERS = new Set([ - "content-type", - "accept", - "accept-encoding", - "accept-language", - "user-agent", - "referer", - "origin", - "authorization", - "proxy-authorization", - "cache-control", -]); - -export const BLOCKED_HEADERS = new Set([ +const BLOCKED_HEADERS = new Set([ "host", - "connection", - "keep-alive", - "proxy-authenticate", - "proxy-authorization", - "te", - "trailers", - "transfer-encoding", - "upgrade", "x-relay-target", "x-relay-path", - "cookie", - "set-cookie", - "x-real-ip", - "x-forwarded-for", - "x-forwarded-host", - "x-forwarded-proto", - "x-api-key", ]); export function normalizeTargetUrl(target: string | null, relayPath: string): string | null { @@ -38,13 +10,9 @@ export function normalizeTargetUrl(target: string | null, relayPath: string): st } export function filterHeaders(headers: Headers): Headers { - const filtered = new Headers(); - for (const [key, value] of headers.entries()) { - const lowerKey = key.toLowerCase(); - if (BLOCKED_HEADERS.has(lowerKey)) continue; - if (lowerKey.startsWith("x-vercel-")) continue; - if (lowerKey.startsWith("cf-")) continue; - filtered.set(key, value); + const filtered = new Headers(headers); + for (const key of BLOCKED_HEADERS) { + filtered.delete(key); } return filtered; } @@ -53,10 +21,7 @@ export function shouldSendBody(method: string): boolean { return method !== "GET" && method !== "HEAD"; } -export function buildRelayRequest( - req: Request, - headers: Headers -): RequestInit { +export function buildRelayRequest(req: Request, headers: Headers): RequestInit { return { method: req.method, headers, @@ -76,13 +41,6 @@ export function isAllowedTarget(url: string): boolean { export function createRelayResponse(response: Response): Response { const headers = new Headers(response.headers); - // Remove headers that would confuse the browser or were handled by the proxy - headers.delete("content-length"); - headers.delete("transfer-encoding"); - headers.delete("connection"); - headers.delete("keep-alive"); - - // Add CORS for browser UI headers.set("Access-Control-Allow-Origin", "*"); headers.set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS"); headers.set("Access-Control-Allow-Headers", "*");