somratpro commited on
Commit
010e97a
·
1 Parent(s): 5d2b465

refactor: remove cloudflare-worker.js and related configurations

Browse files
Files changed (3) hide show
  1. Dockerfile +0 -1
  2. README.md +0 -1
  3. cloudflare-worker.js +0 -103
Dockerfile CHANGED
@@ -181,7 +181,6 @@ COPY health-server.js /opt/healthsrv/health-server.js
181
  COPY postiz-sync.py /opt/postiz-sync.py
182
  COPY cloudflare-proxy.js /opt/cloudflare-proxy.js
183
  COPY cloudflare-proxy-setup.py /opt/cloudflare-proxy-setup.py
184
- COPY cloudflare-worker.js /opt/cloudflare-worker.js
185
  COPY cloudflare-keepalive-setup.py /opt/cloudflare-keepalive-setup.py
186
 
187
  # Vendor fonts + patch script available at runtime.
 
181
  COPY postiz-sync.py /opt/postiz-sync.py
182
  COPY cloudflare-proxy.js /opt/cloudflare-proxy.js
183
  COPY cloudflare-proxy-setup.py /opt/cloudflare-proxy-setup.py
 
184
  COPY cloudflare-keepalive-setup.py /opt/cloudflare-keepalive-setup.py
185
 
186
  # Vendor fonts + patch script available at runtime.
README.md CHANGED
@@ -174,7 +174,6 @@ HuggingPost/
174
  ├── postiz-sync.py # Backup/restore DB + uploads to HF Dataset
175
  ├── cloudflare-proxy.js # Transparent outbound proxy injected via NODE_OPTIONS
176
  ├── cloudflare-proxy-setup.py
177
- ├── cloudflare-worker.js
178
  ├── cloudflare-keepalive-setup.py
179
  ├── docker-compose.yml # Local dev convenience
180
  ├── .env.example # Configuration reference
 
174
  ├── postiz-sync.py # Backup/restore DB + uploads to HF Dataset
175
  ├── cloudflare-proxy.js # Transparent outbound proxy injected via NODE_OPTIONS
176
  ├── cloudflare-proxy-setup.py
 
177
  ├── cloudflare-keepalive-setup.py
178
  ├── docker-compose.yml # Local dev convenience
179
  ├── .env.example # Configuration reference
cloudflare-worker.js DELETED
@@ -1,103 +0,0 @@
1
- /**
2
- * Cloudflare Worker: Universal Outbound Proxy
3
- *
4
- * Manual setup:
5
- * 1. Create a Cloudflare Worker.
6
- * 2. Paste this file and deploy it.
7
- * 3. Use the worker URL as CLOUDFLARE_PROXY_URL.
8
- *
9
- * Optional worker vars:
10
- * - PROXY_SHARED_SECRET
11
- * - ALLOWED_TARGETS
12
- * - ALLOW_PROXY_ALL
13
- */
14
-
15
- function normalizeList(raw) {
16
- return String(raw || "")
17
- .split(",")
18
- .map((value) => value.trim().toLowerCase())
19
- .filter(Boolean);
20
- }
21
-
22
- export default {
23
- async fetch(request, env) {
24
- const url = new URL(request.url);
25
- const queryTarget = url.searchParams.get("proxy_target");
26
- const targetHost = request.headers.get("x-target-host") || queryTarget;
27
- const proxySecret = (
28
- env.PROXY_SHARED_SECRET ||
29
- env.CLOUDFLARE_PROXY_SECRET ||
30
- ""
31
- ).trim();
32
-
33
- if (proxySecret) {
34
- const providedSecret = request.headers.get("x-proxy-key") || url.searchParams.get("proxy_key") || "";
35
- if (providedSecret !== proxySecret) {
36
- // Fallback: allow Telegram requests via path without secret if it looks like a bot API call.
37
- // This is safe because it only proxies to api.telegram.org.
38
- if (url.pathname.startsWith("/bot") && !targetHost) {
39
- // Allowed
40
- } else {
41
- return new Response("Unauthorized: Invalid proxy key", { status: 401 });
42
- }
43
- }
44
- }
45
-
46
- const allowProxyAll =
47
- String(env.ALLOW_PROXY_ALL || "true").toLowerCase() === "true";
48
- const allowedTargets = normalizeList(
49
- env.ALLOWED_TARGETS || "api.telegram.org,discord.com,discordapp.com,gateway.discord.gg,status.discord.com,web.whatsapp.com,graph.facebook.com,googleapis.com,google.com,googleusercontent.com,gstatic.com",
50
- );
51
-
52
- const isAllowedHost = (hostname) => {
53
- const normalized = String(hostname || "")
54
- .trim()
55
- .toLowerCase();
56
- if (!normalized) return false;
57
- if (allowProxyAll) return true;
58
- return allowedTargets.some(
59
- (domain) => normalized === domain || normalized.endsWith(`.${domain}`),
60
- );
61
- };
62
-
63
- let targetBase = "";
64
- if (targetHost) {
65
- if (!isAllowedHost(targetHost)) {
66
- return new Response(`Forbidden: Host ${targetHost} is not allowed.`, { status: 403 });
67
- }
68
- targetBase = `https://${targetHost}`;
69
- } else if (url.pathname.startsWith("/bot")) {
70
- targetBase = "https://api.telegram.org";
71
- } else {
72
- return new Response("Invalid request: No target host provided.", { status: 400 });
73
- }
74
-
75
- const cleanSearch = new URLSearchParams(url.search);
76
- cleanSearch.delete("proxy_target");
77
- cleanSearch.delete("proxy_key");
78
- const searchStr = cleanSearch.toString();
79
- const targetUrl = targetBase + url.pathname + (searchStr ? `?${searchStr}` : "");
80
-
81
- const headers = new Headers(request.headers);
82
- headers.delete("cf-connecting-ip");
83
- headers.delete("cf-ray");
84
- headers.delete("cf-visitor");
85
- headers.delete("host");
86
- headers.delete("x-real-ip");
87
- headers.delete("x-target-host");
88
- headers.delete("x-proxy-key");
89
-
90
- const proxiedRequest = new Request(targetUrl, {
91
- method: request.method,
92
- headers,
93
- body: request.body,
94
- redirect: "follow",
95
- });
96
-
97
- try {
98
- return await fetch(proxiedRequest);
99
- } catch (error) {
100
- return new Response(`Proxy Error: ${error.message}`, { status: 502 });
101
- }
102
- },
103
- };