MCPcopy Create free account
hub / github.com/Ridter/cf_workers_proxy / fetch

Function fetch

js/worker.js:23–52  ·  view source on GitHub ↗

* @param {import("@cloudflare/workers-types").Request} request * @param {{UUID: string, PROXYIP: string}} env * @param {import("@cloudflare/workers-types").ExecutionContext} ctx * @returns {Promise }

(request, env, ctx)

Source from the content-addressed store, hash-verified

21 * @returns {Promise<Response>}
22 */
23 async fetch(request, env, ctx) {
24 try {
25 userID = env.UUID || userID;
26 proxyIP = env.PROXYIP || proxyIP;
27 const upgradeHeader = request.headers.get('Upgrade');
28 if (!upgradeHeader || upgradeHeader !== 'websocket') {
29 const url = new URL(request.url);
30 switch (url.pathname) {
31 case '/':
32 return new Response('Hello World!');
33 case `/${userID}`: {
34 const vlessConfig = getVLESSConfig(userID, request.headers.get('Host'));
35 return new Response(`${vlessConfig}`, {
36 status: 200,
37 headers: {
38 "Content-Type": "text/plain;charset=utf-8",
39 }
40 });
41 }
42 default:
43 return new Response('Not found', { status: 404 });
44 }
45 } else {
46 return await vlessOverWSHandler(request);
47 }
48 } catch (err) {
49 /** @type {Error} */ let e = err;
50 return new Response(e.toString());
51 }
52 },
53};
54
55

Callers 1

writeFunction · 0.85

Calls 2

getVLESSConfigFunction · 0.85
vlessOverWSHandlerFunction · 0.85

Tested by

no test coverage detected