ci: add CF Workers deploy workflow + fix relay header forwarding
This commit is contained in:
@@ -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
@@ -1,35 +1,7 @@
|
|||||||
export const ALLOWED_HEADERS = new Set([
|
const BLOCKED_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([
|
|
||||||
"host",
|
"host",
|
||||||
"connection",
|
|
||||||
"keep-alive",
|
|
||||||
"proxy-authenticate",
|
|
||||||
"proxy-authorization",
|
|
||||||
"te",
|
|
||||||
"trailers",
|
|
||||||
"transfer-encoding",
|
|
||||||
"upgrade",
|
|
||||||
"x-relay-target",
|
"x-relay-target",
|
||||||
"x-relay-path",
|
"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 {
|
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 {
|
export function filterHeaders(headers: Headers): Headers {
|
||||||
const filtered = new Headers();
|
const filtered = new Headers(headers);
|
||||||
for (const [key, value] of headers.entries()) {
|
for (const key of BLOCKED_HEADERS) {
|
||||||
const lowerKey = key.toLowerCase();
|
filtered.delete(key);
|
||||||
if (BLOCKED_HEADERS.has(lowerKey)) continue;
|
|
||||||
if (lowerKey.startsWith("x-vercel-")) continue;
|
|
||||||
if (lowerKey.startsWith("cf-")) continue;
|
|
||||||
filtered.set(key, value);
|
|
||||||
}
|
}
|
||||||
return filtered;
|
return filtered;
|
||||||
}
|
}
|
||||||
@@ -53,10 +21,7 @@ export function shouldSendBody(method: string): boolean {
|
|||||||
return method !== "GET" && method !== "HEAD";
|
return method !== "GET" && method !== "HEAD";
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildRelayRequest(
|
export function buildRelayRequest(req: Request, headers: Headers): RequestInit {
|
||||||
req: Request,
|
|
||||||
headers: Headers
|
|
||||||
): RequestInit {
|
|
||||||
return {
|
return {
|
||||||
method: req.method,
|
method: req.method,
|
||||||
headers,
|
headers,
|
||||||
@@ -76,13 +41,6 @@ export function isAllowedTarget(url: string): boolean {
|
|||||||
|
|
||||||
export function createRelayResponse(response: Response): Response {
|
export function createRelayResponse(response: Response): Response {
|
||||||
const headers = new Headers(response.headers);
|
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-Origin", "*");
|
||||||
headers.set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
|
headers.set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
|
||||||
headers.set("Access-Control-Allow-Headers", "*");
|
headers.set("Access-Control-Allow-Headers", "*");
|
||||||
|
|||||||
Reference in New Issue
Block a user