Skip to content

Commit af427aa

Browse files
committed
Proxy no longer rewrites hostname, instead uses worker origin request forwarding
1 parent 212f853 commit af427aa

File tree

2 files changed

+4
-21
lines changed

2 files changed

+4
-21
lines changed

apps/proxy/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"private": true,
55
"scripts": {
66
"deploy": "wrangler deploy",
7-
"dev": "wrangler dev"
7+
"dev": "wrangler dev",
8+
"dry-run:staging": "wrangler deploy --dry-run --outdir=dist --env staging"
89
},
910
"devDependencies": {
1011
"@cloudflare/workers-types": "^4.20240512.0",

apps/proxy/src/index.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@ export interface Env {
1717

1818
export default {
1919
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
20-
if (!env.REWRITE_HOSTNAME) throw new Error("Missing REWRITE_HOSTNAME");
21-
console.log("url", request.url);
22-
2320
if (!queueingIsEnabled(env)) {
2421
console.log("Missing AWS credentials. Passing through to the origin.");
25-
return redirectToOrigin(request, env);
22+
return fetch(request);
2623
}
2724

2825
const url = new URL(request.url);
@@ -42,25 +39,10 @@ export default {
4239
}
4340

4441
//the same request but with the hostname (and port) changed
45-
return redirectToOrigin(request, env);
42+
return fetch(request);
4643
},
4744
};
4845

49-
function redirectToOrigin(request: Request, env: Env) {
50-
const newUrl = new URL(request.url);
51-
newUrl.hostname = env.REWRITE_HOSTNAME;
52-
newUrl.port = env.REWRITE_PORT || newUrl.port;
53-
54-
const requestInit: RequestInit = {
55-
method: request.method,
56-
headers: request.headers,
57-
body: request.body,
58-
};
59-
60-
console.log("rewritten url", newUrl.toString());
61-
return fetch(newUrl.toString(), requestInit);
62-
}
63-
6446
function queueingIsEnabled(env: Env) {
6547
return (
6648
env.AWS_SQS_ACCESS_KEY_ID &&

0 commit comments

Comments
 (0)