8
8
* Learn more at https://developers.cloudflare.com/workers/
9
9
*/
10
10
11
- import handleProxy from './proxy' ;
12
- import handleRedirect from './redirect' ;
13
- import apiRouter from './router' ;
14
-
15
11
// Export a default object containing event handlers
16
12
export default {
17
13
// The fetch handler is invoked when this worker receives a HTTP(S) request
@@ -20,27 +16,26 @@ export default {
20
16
// You'll find it helpful to parse the request.url string into a URL object. Learn more at https://developer.mozilla.org/en-US/docs/Web/API/URL
21
17
const url = new URL ( request . url ) ;
22
18
23
- // You can get pretty far with simple logic like if/switch-statements
24
- switch ( url . pathname ) {
25
- case '/redirect' :
26
- return handleRedirect . fetch ( request , env , ctx ) ;
19
+ if ( url . pathname != "/mitm/session/minecraft/hasJoined" ) return new Response ( ) ;
20
+
21
+ console . log ( url . href ) ;
27
22
28
- case '/proxy' :
29
- return handleProxy . fetch ( request , env , ctx ) ;
30
- }
31
23
32
- if ( url . pathname . startsWith ( '/api/' ) ) {
33
- // You can also use more robust routing
34
- return apiRouter . handle ( request ) ;
24
+ async function getAuthenticatedUser ( ) {
25
+ const newURLList = [ "https://sessionserver.mojang.com/session/minecraft/hasJoined" , "https://api.minehut.com/mitm/proxy/session/minecraft/hasJoined" ] ;
26
+ for ( const newURL of newURLList ) {
27
+ const newRequestURL = newURL + url . search ;
28
+ const modifiedRequest = new Request ( newRequestURL ) ;
29
+ const response = await fetch ( modifiedRequest ) ;
30
+ if ( response . status == 204 ) {
31
+ continue ;
32
+ }
33
+ return response ;
34
+ }
35
+ //return page with no content
36
+ return new Response ( null , { status : 204 } ) ;
35
37
}
36
38
37
- return new Response (
38
- `Try making requests to:
39
- <ul>
40
- <li><code><a href="/redirect?redirectUrl=https://example.com/">/redirect?redirectUrl=https://example.com/</a></code>,</li>
41
- <li><code><a href="/proxy?modify&proxyUrl=https://example.com/">/proxy?modify&proxyUrl=https://example.com/</a></code>, or</li>
42
- <li><code><a href="/api/todos">/api/todos</a></code></li>` ,
43
- { headers : { 'Content-Type' : 'text/html' } }
44
- ) ;
39
+ return getAuthenticatedUser ( ) ;
45
40
} ,
46
41
} ;
0 commit comments