1
0
zjcqoo 6 жил өмнө
parent
commit
1a547fc526
3 өөрчлөгдсөн 13 нэмэгдсэн , 14 устгасан
  1. 1 1
      README.md
  2. 1 1
      allowed-sites.conf
  3. 11 12
      cf-worker/index.js

+ 1 - 1
README.md

@@ -33,7 +33,7 @@ curl https://raw.githubusercontent.com/EtherDream/jsproxy/dev/i.sh | bash
 测试: `https://服务器IP.xip.io:8443`(具体参考脚本输出)
 
 
-## 部署
+# 部署
 
 Fork 本项目,进入 `gh-pages` 分支,编辑 `conf.js` 文件:
 

+ 1 - 1
allowed-sites.conf

@@ -14,7 +14,7 @@ http://localhost:8080             'lo';
 ''                                'mysite';
 
 # ~ 开头为正则匹配,此处允许 github.io 所有子站点
-~^https://([\w-]+)\.github\.io$     'gh-$1';
+~^https://([\w-]+)\.github\.io$   'gh-$1';
 
 # 允许任何站点使用
 # ~(.*)                             '$1';

+ 11 - 12
cf-worker/index.js

@@ -4,7 +4,7 @@
  */
 'use strict'
 
-const JS_VER = 3
+const JS_VER = 4
 
 const PREFLIGHT_INIT = {
   status: 204,
@@ -16,13 +16,9 @@ const PREFLIGHT_INIT = {
   }),
 }
 
-const pairs = Object.entries
-
 
 addEventListener('fetch', e => {
   const ret = handler(e.request)
-    .catch(err => new Response(err))
-
   e.respondWith(ret)
 })
 
@@ -87,23 +83,26 @@ async function handler(req) {
     }
   }
   if (extHdrs) {
-    for (const [k, v] of pairs(extHdrs)) {
+    for (const [k, v] of Object.entries(extHdrs)) {
       reqHdrNew.set(k, v)
     }
   }
-  return proxy(urlObj, req.method, reqHdrNew, acehOld, rawLen, 0)
+  const reqInit = {
+    method: req.method,
+    headers: reqHdrNew,
+  }
+  return proxy(urlObj, reqInit, acehOld, rawLen, 0)
 }
 
 
 /**
  * 
  * @param {URL} urlObj 
- * @param {string} method 
- * @param {Headers} headers 
+ * @param {RequestInit} reqInit 
  * @param {number} retryTimes 
  */
-async function proxy(urlObj, method, headers, acehOld, rawLen, retryTimes) {
-  const res = await fetch(urlObj.href, {method, headers})
+async function proxy(urlObj, reqInit, acehOld, rawLen, retryTimes) {
+  const res = await fetch(urlObj.href, reqInit)
   const resHdrOld = res.headers
   const resHdrNew = new Headers(resHdrOld)
 
@@ -159,7 +158,7 @@ async function proxy(urlObj, method, headers, acehOld, rawLen, retryTimes) {
     if (retryTimes < 1) {
       urlObj = await parseYtVideoRedir(urlObj, newLen, res)
       if (urlObj) {
-        return proxy(urlObj, method, headers, acehOld, rawLen, retryTimes + 1)
+        return proxy(urlObj, reqInit, acehOld, rawLen, retryTimes + 1)
       }
     }
     status = 400