diff --git a/src/env.ts b/src/env.ts index 20f9a69..3ad8121 100644 --- a/src/env.ts +++ b/src/env.ts @@ -2,12 +2,7 @@ export interface FetcherLike { fetch(request: Request): Promise; } -export interface DispatchNamespaceLike { - get(name: string, scriptArgs?: Record, options?: Record): FetcherLike; -} - export interface Env { AUTH: FetcherLike; - DISPATCHER?: DispatchNamespaceLike; DEFAULT_WORKER_NAME: string; } diff --git a/src/index.ts b/src/index.ts index a0fbc27..02bafc7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,21 +18,10 @@ app.all("*", async (c) => { return c.env.AUTH.fetch(c.req.raw); } - if (!c.env.DISPATCHER) { - return c.json({ - ok: true, - routedTo: target.workerName, - }); - } - - const worker = c.env.DISPATCHER.get(target.workerName, {}, { - limits: { - cpuMs: 20, - subRequests: 20, - }, + return c.json({ + ok: true, + routedTo: target.workerName, }); - - return worker.fetch(c.req.raw); }); export default app; diff --git a/tests/gateway-worker.test.ts b/tests/gateway-worker.test.ts index 555414a..f51c96c 100644 --- a/tests/gateway-worker.test.ts +++ b/tests/gateway-worker.test.ts @@ -43,7 +43,7 @@ describe("cfw-gateway worker", () => { 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 env: Env = { AUTH: auth, @@ -58,39 +58,4 @@ describe("cfw-gateway worker", () => { }); 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(); - }); }); diff --git a/wrangler.jsonc b/wrangler.jsonc index b83d4cf..426f2ba 100644 --- a/wrangler.jsonc +++ b/wrangler.jsonc @@ -2,8 +2,11 @@ "$schema": "node_modules/wrangler/config-schema.json", "name": "cfw-gateway", "main": "src/index.ts", + "account_id": "67720b647ff2b55cf37ba3ef9e677083", "compatibility_date": "2026-06-10", - "compatibility_flags": ["nodejs_compat"], + "compatibility_flags": [ + "nodejs_compat" + ], "routes": [ { "pattern": "cfw-gateway.bowong.cc", @@ -18,11 +21,5 @@ "binding": "AUTH", "service": "cfw-auth" } - ], - "dispatch_namespaces": [ - { - "binding": "DISPATCHER", - "namespace": "platform-workers" - } ] }