The Node upgrade listener only intercepted /__mesh__/control when a mesh control channel was configured; otherwise a user @Ws route there was served. app.upgrade (Deno, Bun, edge) always checked the path first and closed 1008. The same app therefore worked on Node and was refused everywhere else. D17 makes the path reserved in every app, mesh or not: - createApp fails when a @Ws, @Stream or HTTP route claims the path, naming the declaration. A literal pattern is checked by equality, a parameterised one (/__mesh__/:x, /__mesh__/:rest*) by matching the reserved path against it. Patterns whose first segment is not the literal __mesh__ (/:org/:repo, /:rest*) still boot: the adapters answer the path before route matching, so those routes never see it. - A route exported by a teapot is checked during the teacup splice. - The Node listener, with no control channel, accepts the upgrade and closes 1008 with the reason app.upgrade gives. The reason is now one shared constant. The check lives in src/http/reserved-paths.ts so CARD-17 can add /__live__ and /__ready__ to the same list. BREAKING CHANGE: an app that declares a route at /__mesh__/control, or a pattern under /__mesh__/ that matches it, now fails createApp. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
82 lines
2.6 KiB
TypeScript
82 lines
2.6 KiB
TypeScript
// Worker entry for the real workerd (Miniflare) integration test.
|
|
// Mirrors test/deno/ws.test.ts's graph so HTTP + WebSocket behavior is proven
|
|
// identically across runtimes. Run via `npm run test:edge` (see test/edge/run.ts).
|
|
import { createApp, Route, Get, Post, Ws, body, ctx, Module } from '../../src/index';
|
|
import { edgeHandler } from '../../src/edge';
|
|
|
|
@Route('/rt')
|
|
class Rt {
|
|
@Get('/hello')
|
|
hello() {
|
|
return { ok: true };
|
|
}
|
|
|
|
// #105: the body limit, read from workerd's own request stream. Small, so every refused body still
|
|
// fits in the socket buffer: a client that is mid-upload when the 413 lands can see ECONNRESET
|
|
// instead, which is the transport racing the answer rather than a different answer.
|
|
@Post('/body', { maxBodyBytes: 1000 })
|
|
body(@body() b: unknown) {
|
|
return { length: String(b).length };
|
|
}
|
|
|
|
@Ws('/echo')
|
|
echo(@ctx() { inbound }: any) {
|
|
return (async function* () {
|
|
for await (const msg of inbound) yield `echo:${msg}`;
|
|
})();
|
|
}
|
|
|
|
// Never reads `inbound`, so every frame the client sends stays queued (#107).
|
|
@Ws('/stall')
|
|
stall() {
|
|
return (async function* () {
|
|
await new Promise<never>(() => {});
|
|
yield '';
|
|
})();
|
|
}
|
|
|
|
@Ws('/room/:name')
|
|
room(@ctx() { inbound }: any) {
|
|
return (async function* () {
|
|
for await (const msg of inbound) yield `room:${msg}`;
|
|
})();
|
|
}
|
|
}
|
|
|
|
@Module({ mountpoint: '/', controllers: [Rt] })
|
|
class M {}
|
|
|
|
const app = createApp({ modules: [M] });
|
|
// #107: the same graph with tight ws limits, reached through the `limited` host.
|
|
const limited = createApp({ modules: [M], limits: { maxWsMessageBytes: 1024, maxWsQueue: 4 } });
|
|
const handlers = { default: edgeHandler(app), limited: edgeHandler(limited) };
|
|
|
|
// CARD-21 (D17): a route on the reserved mesh path must fail createApp inside workerd too. Built per
|
|
// request on the `reserved` host so a regression answers with a status instead of breaking the worker.
|
|
@Route('/')
|
|
class Claims {
|
|
@Ws('/__mesh__/control')
|
|
control() {
|
|
return (async function* () {})();
|
|
}
|
|
}
|
|
@Module({ mountpoint: '/', controllers: [Claims] })
|
|
class ClaimsModule {}
|
|
|
|
function reservedBoot(): Response {
|
|
try {
|
|
createApp({ modules: [ClaimsModule] });
|
|
} catch (error) {
|
|
return new Response((error as Error).message, { status: 500 });
|
|
}
|
|
return new Response('booted', { status: 200 });
|
|
}
|
|
|
|
export default {
|
|
fetch: (request: Request, env?: unknown, ctx?: Parameters<typeof handlers.default>[2]) => {
|
|
const host = new URL(request.url).hostname;
|
|
if (host === 'reserved') return reservedBoot();
|
|
return (host === 'limited' ? handlers.limited : handlers.default)(request, env, ctx);
|
|
},
|
|
};
|