first working ver
This commit is contained in:
24
package-lock.json
generated
24
package-lock.json
generated
@@ -7,8 +7,12 @@
|
||||
"": {
|
||||
"name": "evilproxy",
|
||||
"version": "0.0.0",
|
||||
"dependencies": {
|
||||
"workers": "^0.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@cloudflare/vitest-pool-workers": "^0.12.4",
|
||||
"@cloudflare/workers-types": "^4.20260605.1",
|
||||
"typescript": "^5.5.2",
|
||||
"vitest": "~3.2.0",
|
||||
"wrangler": "^3.101.0"
|
||||
@@ -217,6 +221,13 @@
|
||||
"node": ">=16"
|
||||
}
|
||||
},
|
||||
"node_modules/@cloudflare/workers-types": {
|
||||
"version": "4.20260605.1",
|
||||
"resolved": "https://registry.npmjs.org/@cloudflare/workers-types/-/workers-types-4.20260605.1.tgz",
|
||||
"integrity": "sha512-9YJaGPQwuQYFHoElVhJP40ZmUO/Z2OiBon58sKpHjgwq5btC/B2BZLC45AQ14k+1I+hjcY2z2t2R6uUxU9AqwQ==",
|
||||
"dev": true,
|
||||
"license": "MIT OR Apache-2.0"
|
||||
},
|
||||
"node_modules/@cspotcode/source-map-support": {
|
||||
"version": "0.8.1",
|
||||
"resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz",
|
||||
@@ -2345,6 +2356,11 @@
|
||||
"node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/node-logr": {
|
||||
"version": "0.5.2",
|
||||
"resolved": "https://registry.npmjs.org/node-logr/-/node-logr-0.5.2.tgz",
|
||||
"integrity": "sha512-roPNxvG+OsefMyfVa5HeO24kRtxA7UB8CtvsR8CfSxaESw+1FTsMf8gkDluG5vppzXrXVCI146PQR2KMaszWig=="
|
||||
},
|
||||
"node_modules/ohash": {
|
||||
"version": "2.0.11",
|
||||
"resolved": "https://registry.npmjs.org/ohash/-/ohash-2.0.11.tgz",
|
||||
@@ -3023,6 +3039,14 @@
|
||||
"@cloudflare/workerd-windows-64": "1.20260310.1"
|
||||
}
|
||||
},
|
||||
"node_modules/workers": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/workers/-/workers-0.0.1.tgz",
|
||||
"integrity": "sha512-cp2HU5tdKyxOiHg7l8p67R2F07vLT1Hd/h3Xi3dXtoO5NlXml4nkJ48O0EmEkOMtWqEZMWAoNLZfctT3qiP3IA==",
|
||||
"dependencies": {
|
||||
"node-logr": ">= 0.0.3"
|
||||
}
|
||||
},
|
||||
"node_modules/wrangler": {
|
||||
"version": "3.114.17",
|
||||
"resolved": "https://registry.npmjs.org/wrangler/-/wrangler-3.114.17.tgz",
|
||||
|
||||
@@ -11,8 +11,12 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@cloudflare/vitest-pool-workers": "^0.12.4",
|
||||
"@cloudflare/workers-types": "^4.20260605.1",
|
||||
"typescript": "^5.5.2",
|
||||
"vitest": "~3.2.0",
|
||||
"wrangler": "^3.101.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"workers": "^0.0.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Hello, World!</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="heading"></h1>
|
||||
<p>This page comes from a static asset stored at `public/index.html` as configured in `wrangler.jsonc`.</p>
|
||||
<button id="button" type="button">Fetch a random UUID</button>
|
||||
<output id="random" for="button"></output>
|
||||
<script>
|
||||
fetch('/message')
|
||||
.then((resp) => resp.text())
|
||||
.then((text) => {
|
||||
const h1 = document.getElementById('heading');
|
||||
h1.textContent = text;
|
||||
});
|
||||
|
||||
const button = document.getElementById("button");
|
||||
button.addEventListener("click", () => {
|
||||
fetch('/random')
|
||||
.then((resp) => resp.text())
|
||||
.then((text) => {
|
||||
const random = document.getElementById('random');
|
||||
random.textContent = text;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
44
src/index.ts
44
src/index.ts
@@ -12,15 +12,35 @@
|
||||
*/
|
||||
|
||||
export default {
|
||||
async fetch(request, env, ctx): Promise<Response> {
|
||||
const url = new URL(request.url);
|
||||
switch (url.pathname) {
|
||||
case '/message':
|
||||
return new Response('Hello, World!');
|
||||
case '/random':
|
||||
return new Response(crypto.randomUUID());
|
||||
default:
|
||||
return new Response('Not Found', { status: 404 });
|
||||
}
|
||||
},
|
||||
} satisfies ExportedHandler<Env>;
|
||||
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
|
||||
|
||||
const targetUrl = 'https://related-digital.com';
|
||||
|
||||
const url = new URL(request.url);
|
||||
|
||||
const destination = `${targetUrl}${url.pathname}${url.search}`;
|
||||
|
||||
const newHeaders = new Headers(request.headers);
|
||||
|
||||
newHeaders.set('Host', new URL(targetUrl).hostname);
|
||||
|
||||
|
||||
newHeaders.set('Referer', targetUrl);
|
||||
|
||||
const proxyRequest = new Request(destination, {
|
||||
method: request.method,
|
||||
headers: newHeaders,
|
||||
body: request.body,
|
||||
redirect: 'follow'
|
||||
});
|
||||
|
||||
try {
|
||||
|
||||
const response = await fetch(proxyRequest);
|
||||
return response;
|
||||
} catch (e) {
|
||||
console.error('Proxy failed:', e);
|
||||
return new Response(`Failed to proxy request to ${targetUrl}`, { status: 502 });
|
||||
}
|
||||
},
|
||||
} satisfies ExportedHandler<Env>;
|
||||
@@ -3,9 +3,9 @@
|
||||
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
||||
|
||||
/* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
||||
"target": "es2024",
|
||||
"target": "es2022",
|
||||
/* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
||||
"lib": ["es2024"],
|
||||
"lib": ["es2022"],
|
||||
/* Specify what JSX code is generated. */
|
||||
"jsx": "react-jsx",
|
||||
|
||||
|
||||
5
worker-configuration.d.ts
vendored
Normal file
5
worker-configuration.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
// Generated by Wrangler by running `wrangler types`
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface,@typescript-eslint/no-empty-object-type
|
||||
interface Env {
|
||||
}
|
||||
@@ -1,14 +1,11 @@
|
||||
{
|
||||
"name": "<WORKER_NAME>",
|
||||
"name": "evilproxy",
|
||||
"main": "src/index.ts",
|
||||
"compatibility_date": "<COMPATIBILITY_DATE>",
|
||||
"compatibility_date": "2026-06-04",
|
||||
"compatibility_flags": [
|
||||
"global_fetch_strictly_public"
|
||||
"global_fetch_strictly_public",
|
||||
"nodejs_compat"
|
||||
],
|
||||
"assets": {
|
||||
// The path to the directory containing the `index.html` file to be served at `/`
|
||||
"directory": "./public"
|
||||
},
|
||||
"observability": {
|
||||
"enabled": true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user