feat: beta-hardening — routing, degradation, mesh gate, uploads, @header

Restructure first: split the two oversized files by cohesion (http.ts 449
→ http/{router,request,stream,ws,server,types}; app.ts 556 → app/{types,
introspect,index}), rename cryptic locals, JSDoc the public API, and
extract helpers so no function exceeds the complexity gate (createApp
187 → <15, listen 113 → 6). Public import paths are unchanged (barrels).

On that structure, five features that close the biggest gaps vs
Express/Fastify/Nest for a comparable beta:

- routing: `:name*` catch-all, specificity precedence (static ▸ param ▸
  catch-all, not registration order), and 405 + Allow when a path exists
  under a different method (was 404)
- visible degradation: optional providers that fail boot are summarized on
  listen() and queryable via app.degraded(), instead of a silent warn
- mesh is alpha — gated behind `experimental: true`; createApp throws if
  `mesh` is configured without it
- multipart moves to the optional `busboy` peer dependency (clear 501 when
  absent), keeping the core at one runtime dependency
- `@header('name')` as a singular alias of `@headers`

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-07-07 12:00:15 -05:00
1 parent 9d79972f62
commit d6c5cee0ee
42 files changed
+2619 -1170

No files matched your search

+6 -3
View File
@@ -187,7 +187,7 @@ describe('CORS', () => {
expect(r.headers.get('access-control-allow-credentials')).toBe('true');
});
it('disallowed origin → no allow-origin; bare OPTIONS (no ACRM) falls through to 404', async () => {
it('disallowed origin → no allow-origin; bare OPTIONS (no ACRM) → 405 Allow for an existing path', async () => {
@Route('/') class C { @Get('/x') x() { return { ok: 1 }; } }
@Module({ mountpoint: '/', controllers: [C] }) class CMod {}
app = createApp({ modules: [CMod], cors: { origins: 'https://a.com' } });
@@ -195,8 +195,11 @@ describe('CORS', () => {
const port = (server.address() as any).port;
const r = await fetch(`http://127.0.0.1:${port}/x`, { headers: { origin: 'https://evil.com' } });
expect(r.headers.get('access-control-allow-origin')).toBeNull();
const bare = await fetch(`http://127.0.0.1:${port}/x`, { method: 'OPTIONS' }); // no ACRM
expect(bare.status).toBe(404);
// A bare OPTIONS (no Access-Control-Request-Method) isn't a CORS preflight; the path exists
// under GET, so the router answers 405 with an Allow header rather than 404.
const bare = await fetch(`http://127.0.0.1:${port}/x`, { method: 'OPTIONS' });
expect(bare.status).toBe(405);
expect(bare.headers.get('allow')).toContain('GET');
});
it("merges a handler's Title-Case Vary with CORS's Origin", async () => {