MCPcopy Create free account
hub / github.com/cmliu/CF-Workers-CheckProxyIP / fetch

Function fetch

_worker.js:30–65  ·  view source on GitHub ↗
(request, env)

Source from the content-addressed store, hash-verified

28const RESOLVE_BATCH_LIMIT = 15;
29export 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
68async function handleResolveBatchRequest(request) {

Callers 1

dohQueryFunction · 0.85

Calls 4

handleCheckProxyRequestFunction · 0.85
handleResolveFunction · 0.85
generateHTMLFunction · 0.85

Tested by

no test coverage detected