From 02cb7c04c0c7892a5307ea7d7e4680403017e90f Mon Sep 17 00:00:00 2001 From: inko <79123545+kerry64@users.noreply.github.com> Date: Sat, 15 Apr 2023 20:58:58 +0800 Subject: [PATCH 1/2] Update index.js solve Cloudflare: Direct IP Access Not Allowed problem, but ipv4 only. --- cf-worker/index.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/cf-worker/index.js b/cf-worker/index.js index d2c1c70d370..541fa1fb384 100644 --- a/cf-worker/index.js +++ b/cf-worker/index.js @@ -5,9 +5,12 @@ */ const ASSET_URL = 'https://etherdream.github.io/jsproxy' -const JS_VER = 10 +const JS_VER = 11 const MAX_RETRY = 1 +const ip_to_dns = '.sslip.io' +// solve Cloudflare: Direct IP Access Not Allowed + /** @type {RequestInit} */ const PREFLIGHT_INIT = { status: 204, @@ -35,7 +38,15 @@ function makeRes(body, status = 200, headers = {}) { */ function newUrl(urlStr) { try { - return new URL(urlStr) + const ipv4=/\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/; + var urlobj = new URL(urlstr) + urlobj.hostname = + ipv4.test(urlobj.hostname) ? + urlobj.hostname + ip_dns_srv //'.sslip.io' + : /*isIPv6(urlobj.hostname) ? + urlobj.hostname.replaceAll(':','-') + ip_dns_srv + :*/ urlobj.hostname + return urlobj } catch (err) { return null } @@ -287,4 +298,4 @@ async function parseYtVideoRedir(urlObj, newLen, res) { return null } return urlObj -} \ No newline at end of file +} From 8112b36e2b5b19b43cff5c7e01d626ef7384dfb6 Mon Sep 17 00:00:00 2001 From: inko <79123545+kerry64@users.noreply.github.com> Date: Thu, 11 Jan 2024 10:45:19 +0800 Subject: [PATCH 2/2] typo --- cf-worker/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cf-worker/index.js b/cf-worker/index.js index 541fa1fb384..7c200416124 100644 --- a/cf-worker/index.js +++ b/cf-worker/index.js @@ -8,7 +8,7 @@ const ASSET_URL = 'https://etherdream.github.io/jsproxy' const JS_VER = 11 const MAX_RETRY = 1 -const ip_to_dns = '.sslip.io' +const ip_dns_srv = '.sslip.io' // solve Cloudflare: Direct IP Access Not Allowed /** @type {RequestInit} */ @@ -39,7 +39,7 @@ function makeRes(body, status = 200, headers = {}) { function newUrl(urlStr) { try { const ipv4=/\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/; - var urlobj = new URL(urlstr) + var urlobj = new URL(urlStr) urlobj.hostname = ipv4.test(urlobj.hostname) ? urlobj.hostname + ip_dns_srv //'.sslip.io'