File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change @@ -14,6 +14,8 @@ rm -f www.tar.gz
1414# add scholar
1515cp scholar.png jsproxy-$JSPROXY_VER /www/assets/ico/
1616patch -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
1921wget -c -O lua-resty-string.tar.gz https://github.com/openresty/lua-resty-string/archive/refs/tags/v0.15.tar.gz
You can’t perform that action at this time.
0 commit comments