feat(routing): support helper middleware#161
Merged
Merged
Conversation
- allow verb helpers to accept middleware before handlers - preserve named and unnamed helper behavior
Contributor
There was a problem hiding this comment.
Pull request overview
Adds middleware support to the function-first HTTP verb helpers (e.g., Get, Post) so callers can supply zero or more middleware functions before the final handler, with optional route naming preserved.
Changes:
- Extends HTTP verb helper signatures to accept
(...middleware, handler)with optional(name, ...middleware, handler). - Updates verb helper argument parsing to extract
middleware[]andhandler, and throws clearer runtime errors when no handler is provided. - Adds/updates unit + E2E tests to validate middleware ordering and named/unnamed helper behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
tests/function-first-routing.e2e.test.ts |
Adds an E2E assertion that verb-helper-declared middleware runs in declaration order; updates a grouped route config test to use Post helper. |
src/routing/helpers/http-verb-helpers.ts |
Implements middleware+handler parsing for verb helpers and wires extracted middleware into Route(...). |
src/routing/helpers/http-verb-helpers.test.ts |
Adds unit tests for middleware extraction and for throwing when handlers are missing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds middleware support to function-first HTTP verb helpers.
HTTP helpers now accept zero or more middleware functions before the final handler, for both named and unnamed routes:
Get('/users', authMiddleware, handler)Get('/users', 'users.list', authMiddleware, handler)The final function argument is treated as the handler. Any preceding functions after the optional route name are treated as route middleware and run before the handler in declaration order.