ci: add CF Workers deploy workflow + fix relay header forwarding

This commit is contained in:
MythEclipse
2026-05-08 18:58:50 +07:00
parent dfb0f5942f
commit 443ff77be9
2 changed files with 36 additions and 47 deletions
+31
View File
@@ -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 }}
+5 -47
View File
@@ -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", "*");