(request, env)
| 28 | const RESOLVE_BATCH_LIMIT = 15; |
| 29 | export default { |
| 30 | async fetch(request, env) { |
| 31 | const 备案内容 = env.BEIAN ?? DEFAULT_BEIAN_CONTENT; |
| 32 | const url = new URL(request.url); |
| 33 | |
| 34 | if (url.pathname === '/check') { |
| 35 | return handleCheckProxyRequest(request); |
| 36 | } else if (url.pathname === '/resolve') { |
| 37 | const proxyip = url.searchParams.get('proxyip'); |
| 38 | if (!proxyip) { |
| 39 | return new Response('Missing proxyip', { status: 400 }); |
| 40 | } |
| 41 | |
| 42 | try { |
| 43 | const targets = await handleResolve(proxyip); |
| 44 | return new Response(JSON.stringify(targets), { |
| 45 | headers: { |
| 46 | 'Content-Type': 'application/json', |
| 47 | 'Access-Control-Allow-Origin': '*' |
| 48 | } |
| 49 | }); |
| 50 | } catch (error) { |
| 51 | return new Response(JSON.stringify({ error: error.message }), { |
| 52 | status: 500, |
| 53 | headers: { |
| 54 | 'Content-Type': 'application/json', |
| 55 | 'Access-Control-Allow-Origin': '*' |
| 56 | } |
| 57 | }); |
| 58 | } |
| 59 | } else if (url.pathname === '/resolve-batch') { |
| 60 | return handleResolveBatchRequest(request); |
| 61 | } else if (url.pathname === '/locations') return fetch(new Request('https://speed.cloudflare.com/locations', { headers: { 'Referer': 'https://speed.cloudflare.com/' } })); |
| 62 | return new Response(generateHTML(备案内容), { |
| 63 | headers: { 'Content-Type': 'text/html; charset=UTF-8' } |
| 64 | }); |
| 65 | } |
| 66 | }; |
| 67 | |
| 68 | async function handleResolveBatchRequest(request) { |
no test coverage detected