Skip to content

middleware: init/dispose lifecycle hooks for connection pools #683

Closed

Description

@blove

Problem

The file-convention middleware (src/middleware.ts exporting defineMiddleware) has no init/dispose hooks. A database pool used by the middleware can only be opened at module scope (or lazily in a memoised getter), and there is no documented way to release it on function shutdown. In the invoicing example this forced a lazy, reset-on-rejection getter pattern that every app will have to reinvent.

Proposal

Optional lifecycle hooks on the middleware definition, e.g. defineMiddleware({ setup(ctx) {…}, dispose() {…}, handle(req, ctx) {…} }), with dispose wired to the runtime shutdown path for each target.

Activity

  1. added
    enhancement
    on Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions