a minimal web framework for deno

extensible context api #3

open opened by cute.kyu.re

summary#

introduce a mechanism to override the default Context instantiation within the Router to allow for framework-level extensions and typed state augmentation

shortcoming#

the Context type is currently hardcoded inside the createRouter implementation. this prevents downstream frameworks (like cobweb) or other kind of advanced applications from extending the Context with additional props (e.g., an HTTP streaming interface, specific session objects, or typed application state) without duplicating the entire router logic or resorting to unsafe operations with undefined behaviour. while ctx.state exists, it’s effectively just a Map which lacks compile-time safety for specific extensions qwq

proposed solution#

Add an optional contextFactory property to the RouterConfig interface, for example:

export interface RouterConfig {
  contextFactory?: <P = Record<string, string>>(
    request: Request,
    url: URL,
    info: Deno.ServeHandlerInfo<Deno.NetAddr>,
    params: P,
    requestId: string,
  ) => Context<P>;
}
sign up or login to add to the discussion
Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:baxmqv3ddi3pg5iolx77lofv/sh.tangled.repo.issue/3mepezvagou22