refactor: remove unused DISPATCHER interface and related code

This commit is contained in:
2026-06-11 00:25:26 -07:00
parent 35798508f3
commit c18350a0f0
4 changed files with 8 additions and 62 deletions

View File

@@ -2,12 +2,7 @@ export interface FetcherLike {
fetch(request: Request): Promise<Response>; fetch(request: Request): Promise<Response>;
} }
export interface DispatchNamespaceLike {
get(name: string, scriptArgs?: Record<string, unknown>, options?: Record<string, unknown>): FetcherLike;
}
export interface Env { export interface Env {
AUTH: FetcherLike; AUTH: FetcherLike;
DISPATCHER?: DispatchNamespaceLike;
DEFAULT_WORKER_NAME: string; DEFAULT_WORKER_NAME: string;
} }

View File

@@ -18,21 +18,10 @@ app.all("*", async (c) => {
return c.env.AUTH.fetch(c.req.raw); return c.env.AUTH.fetch(c.req.raw);
} }
if (!c.env.DISPATCHER) { return c.json({
return c.json({ ok: true,
ok: true, routedTo: target.workerName,
routedTo: target.workerName,
});
}
const worker = c.env.DISPATCHER.get(target.workerName, {}, {
limits: {
cpuMs: 20,
subRequests: 20,
},
}); });
return worker.fetch(c.req.raw);
}); });
export default app; export default app;

View File

@@ -43,7 +43,7 @@ describe("cfw-gateway worker", () => {
expect(auth.fetch).toHaveBeenCalledOnce(); expect(auth.fetch).toHaveBeenCalledOnce();
}); });
it("routes non-auth requests without consulting auth service when dispatcher is absent", async () => { it("routes non-auth requests without consulting auth service", async () => {
const auth = createAuthService(401, { authenticated: false }); const auth = createAuthService(401, { authenticated: false });
const env: Env = { const env: Env = {
AUTH: auth, AUTH: auth,
@@ -58,39 +58,4 @@ describe("cfw-gateway worker", () => {
}); });
expect(auth.fetch).not.toHaveBeenCalled(); expect(auth.fetch).not.toHaveBeenCalled();
}); });
it("dispatches non-auth requests without injecting identity headers", async () => {
const dispatchedFetch = vi.fn(async (request: Request) => {
return Response.json({
authorization: request.headers.get("authorization"),
requestId: request.headers.get("x-request-id"),
});
});
const auth = createAuthService(401, { authenticated: false });
const env: Env = {
AUTH: auth,
DISPATCHER: {
get: vi.fn(() => ({ fetch: dispatchedFetch })),
},
DEFAULT_WORKER_NAME: "customer-worker-1",
};
const response = await worker.fetch(
new Request("http://gateway.local/app", {
headers: {
authorization: "Bearer real-client-token",
"x-request-id": "client-request-1",
},
}),
env,
);
expect(response.status).toBe(200);
await expect(response.json()).resolves.toEqual({
authorization: "Bearer real-client-token",
requestId: "client-request-1",
});
expect(auth.fetch).not.toHaveBeenCalled();
expect(dispatchedFetch).toHaveBeenCalledOnce();
});
}); });

View File

@@ -2,8 +2,11 @@
"$schema": "node_modules/wrangler/config-schema.json", "$schema": "node_modules/wrangler/config-schema.json",
"name": "cfw-gateway", "name": "cfw-gateway",
"main": "src/index.ts", "main": "src/index.ts",
"account_id": "67720b647ff2b55cf37ba3ef9e677083",
"compatibility_date": "2026-06-10", "compatibility_date": "2026-06-10",
"compatibility_flags": ["nodejs_compat"], "compatibility_flags": [
"nodejs_compat"
],
"routes": [ "routes": [
{ {
"pattern": "cfw-gateway.bowong.cc", "pattern": "cfw-gateway.bowong.cc",
@@ -18,11 +21,5 @@
"binding": "AUTH", "binding": "AUTH",
"service": "cfw-auth" "service": "cfw-auth"
} }
],
"dispatch_namespaces": [
{
"binding": "DISPATCHER",
"namespace": "platform-workers"
}
] ]
} }