Skip to content

Commit 0eec27d

Browse files
committed
add jsproxy patch from EtherDream/jsproxy/pull/202
1 parent d6b7c6c commit 0eec27d

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

etc/jsproxy/cf-worker-index.patch

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
diff -Nur cf-worker/index.js cf-worker-ws/index.js
2+
--- cf-worker/index.js 2019-07-26 22:48:00.000000000 +0800
3+
+++ cf-worker-ws/index.js 2022-10-10 21:01:05.000000000 +0800
4+
@@ -69,12 +69,13 @@
5+
if (path.startsWith('/http/')) {
6+
return httpHandler(req, path.substr(6))
7+
}
8+
+ if (path.startsWith('/ws')) {
9+
+ return wsHandler(req)
10+
+ }
11+
12+
switch (path) {
13+
case '/http':
14+
return makeRes('请更新 cfworker 到最新版本!')
15+
- case '/ws':
16+
- return makeRes('not support', 400)
17+
case '/works':
18+
return makeRes('it works')
19+
default:
20+
@@ -83,6 +84,27 @@
21+
}
22+
}
23+
24+
+/**
25+
+ * @param {Request} req
26+
+ */
27+
+function wsHandler(req) {
28+
+ const urlObj = new URL(req.url);
29+
+ const origin = urlObj.searchParams.get('origin');
30+
+ const targeturl = urlObj.searchParams.get('url__');
31+
+
32+
+ const headers = new Headers(req.headers);
33+
+ origin !== undefined && headers.set('origin', origin);
34+
+
35+
+ return fetch(targeturl, {
36+
+ method: req.method,
37+
+ headers,
38+
+ body: req.body,
39+
+ redirect: 'follow',
40+
+ }).catch((err) => {
41+
+ console.log(err)
42+
+ throw err;
43+
+ });
44+
+}
45+
46+
/**
47+
* @param {Request} req

etc/jsproxy/download.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ rm -f www.tar.gz
1414
# add scholar
1515
cp scholar.png jsproxy-$JSPROXY_VER/www/assets/ico/
1616
patch -b -p1 -d jsproxy-$JSPROXY_VER/www -i ../../www-index_v3.patch
17+
# edit cf-worker/index.js for /ws
18+
patch -b -p1 -d jsproxy-$JSPROXY_VER/cf-worker -i ../../cf-worker-index.patch
1719

1820
# resty/?.lua
1921
wget -c -O lua-resty-string.tar.gz https://github.com/openresty/lua-resty-string/archive/refs/tags/v0.15.tar.gz

0 commit comments

Comments
 (0)