diff --git a/cf-worker/index.js b/cf-worker/index.js index d2c1c70d370..7c200416124 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_dns_srv = '.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 +}