Skip to content

feat: composable per-action middleware with typed context #490

@vivek7405

Description

@vivek7405

Sub-issue of #488. webjs has root + per-segment middleware.js but no composable PER-ACTION middleware that accumulates typed context (auth, logging, rate-limit, db transaction declared on the action). TanStack Start models this well with createMiddleware (request + function middleware types, typed context accumulation through the chain, per-middleware validators).

Design / approach

A composable per-action middleware primitive that runs around an action's execution (RPC path and route.ts boundary), accumulating typed context the handler receives. It must compose with the #488 config-export model (a sibling export const middleware = [...] on the action file) and with validate. Decide: a createMiddleware-style builder vs a plain array of (ctx, next) => ... functions (webjs's existing middleware shape). Typed context accumulation is the hard, high-value part for DX. Server-only.

Acceptance criteria

  • An action declares middleware that runs before/after it, on the RPC and route.ts paths.
  • Middleware accumulates typed context the handler receives (TS inference through the chain).
  • Short-circuit (an auth middleware returning a 401) works.
  • Composes with validate and the verb/cache config.
  • Tests every layer + docs.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type
No fields configured for issues without a type.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions