@@ -6,7 +6,7 @@ import { connect } from 'cloudflare:sockets';
66// [Windows] Press "Win + R", input cmd and run: Powershell -NoExit -Command "[guid]::NewGuid()"
77let userID = '90cd4a77-141a-43c9-991b-08263cfe9c10' ;
88
9- let proxyIP = '' ; // 小白勿动,该地址并不影响你的网速,这是给CF代理使用的。'cdn.xn--b6gac.eu.org, cdn-all.xn--b6gac.eu.org, workers.cloudflare.cyou '
9+ let proxyIP = '' ; // 小白勿动,该地址并不影响你的网速,这是给CF代理使用的。'cdn.xn--b6gac.eu.org, cdn-all.xn--b6gac.eu.org'
1010
1111let sub = '' ; // 避免项目被滥用,现已取消内置订阅器
1212let subconverter = 'SUBAPI.fxxk.dedyn.io' ; // clash订阅转换后端,目前使用CM的订阅转换功能。自带虚假uuid和host订阅。
@@ -148,13 +148,9 @@ export default {
148148 // const url = new URL(request.url);
149149 switch ( url . pathname . toLowerCase ( ) ) {
150150 case '/' :
151- const envKey = env . URL302 ? 'URL302' : ( env . URL ? 'URL' : null ) ;
152- if ( envKey ) {
153- const URLs = await ADD ( env [ envKey ] ) ;
154- const URL = URLs [ Math . floor ( Math . random ( ) * URLs . length ) ] ;
155- return envKey === 'URL302' ? Response . redirect ( URL , 302 ) : fetch ( new Request ( URL , request ) ) ;
156- }
157- return new Response ( JSON . stringify ( request . cf , null , 4 ) , { status : 200 } ) ;
151+ if ( env . URL302 ) return Response . redirect ( env . URL302 , 302 ) ;
152+ else if ( env . URL ) return await proxyURL ( env . URL , url ) ;
153+ else return new Response ( JSON . stringify ( request . cf , null , 4 ) , { status : 200 } ) ;
158154 case `/${ fakeUserID } ` :
159155 const fakeConfig = await getVLESSConfig ( userID , request . headers . get ( 'Host' ) , sub , 'CF-Workers-SUB' , RproxyIP , url ) ;
160156 return new Response ( `${ fakeConfig } ` , { status : 200 } ) ;
@@ -208,7 +204,9 @@ export default {
208204 }
209205 }
210206 default :
211- return new Response ( 'Not found' , { status : 404 } ) ;
207+ if ( env . URL302 ) return Response . redirect ( env . URL302 , 302 ) ;
208+ else if ( env . URL ) return await proxyURL ( env . URL , url ) ;
209+ else return new Response ( '不用怀疑!你UUID就是错的!!!' , { status : 404 } ) ;
212210 }
213211 } else {
214212 proxyIP = url . searchParams . get ( 'proxyip' ) || proxyIP ;
@@ -414,7 +412,15 @@ async function handleTCPOutBound(remoteSocket, addressType, addressRemote, portR
414412 tcpSocket = await connectAndWrite ( addressRemote , portRemote , true ) ;
415413 } else {
416414 // 否则,尝试使用预设的代理 IP(如果有)或原始地址重试连接
417- if ( ! proxyIP || proxyIP == '' ) proxyIP = atob ( 'cHJveHlpcC5meHhrLmRlZHluLmlv' ) ;
415+ if ( ! proxyIP || proxyIP == '' ) {
416+ proxyIP = atob ( 'cHJveHlpcC5meHhrLmRlZHluLmlv' ) ;
417+ } else if ( proxyIP . includes ( ']:' ) ) {
418+ portRemote = proxyIP . split ( ']:' ) [ 1 ] || portRemote ;
419+ proxyIP = proxyIP . split ( ']:' ) [ 0 ] || proxyIP ;
420+ } else if ( proxyIP . split ( ':' ) . length === 2 ) {
421+ portRemote = proxyIP . split ( ':' ) [ 1 ] || portRemote ;
422+ proxyIP = proxyIP . split ( ':' ) [ 0 ] || proxyIP ;
423+ }
418424 tcpSocket = await connectAndWrite ( proxyIP || addressRemote , portRemote ) ;
419425 }
420426 // 无论重试是否成功,都要关闭 WebSocket(可能是为了重新建立连接)
@@ -1195,6 +1201,46 @@ async function ADD(envadd) {
11951201 return add ;
11961202}
11971203
1204+ async function proxyURL ( proxyURL , url ) {
1205+ const URLs = await ADD ( proxyURL ) ;
1206+ const fullURL = URLs [ Math . floor ( Math . random ( ) * URLs . length ) ] ;
1207+
1208+ // 解析目标 URL
1209+ let parsedURL = new URL ( fullURL ) ;
1210+ console . log ( parsedURL ) ;
1211+ // 提取并可能修改 URL 组件
1212+ let URLProtocol = parsedURL . protocol . slice ( 0 , - 1 ) || 'https' ;
1213+ let URLHostname = parsedURL . hostname ;
1214+ let URLPathname = parsedURL . pathname ;
1215+ let URLSearch = parsedURL . search ;
1216+
1217+ // 处理 pathname
1218+ if ( URLPathname . charAt ( URLPathname . length - 1 ) == '/' ) {
1219+ URLPathname = URLPathname . slice ( 0 , - 1 ) ;
1220+ }
1221+ URLPathname += url . pathname ;
1222+
1223+ // 构建新的 URL
1224+ let newURL = `${ URLProtocol } ://${ URLHostname } ${ URLPathname } ${ URLSearch } ` ;
1225+
1226+ // 反向代理请求
1227+ let response = await fetch ( newURL ) ;
1228+
1229+ // 创建新的响应
1230+ let newResponse = new Response ( response . body , {
1231+ status : response . status ,
1232+ statusText : response . statusText ,
1233+ headers : response . headers
1234+ } ) ;
1235+
1236+ // 添加自定义头部,包含 URL 信息
1237+ //newResponse.headers.set('X-Proxied-By', 'Cloudflare Worker');
1238+ //newResponse.headers.set('X-Original-URL', fullURL);
1239+ newResponse . headers . set ( 'X-New-URL' , newURL ) ;
1240+
1241+ return newResponse ;
1242+ }
1243+
11981244function checkSUB ( host ) {
11991245 if ( ( ! sub || sub == '' ) && ( addresses . length + addressesapi . length + addressesnotls . length + addressesnotlsapi . length + addressescsv . length ) == 0 ) {
12001246 addresses = [
0 commit comments