Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for middleware. #2

Merged
merged 2 commits into from
Jan 12, 2024
Merged

Add support for middleware. #2

merged 2 commits into from
Jan 12, 2024

Conversation

paddycarver
Copy link
Contributor

Add helper methods that will support middleware both at the endpoint level and at the router level. This allows us a cleaner interface for setting middleware on an endpoint (before it was just nested functions with lots of parens) and significantly cleans up endpoints when using, e.g., log injection middleware that you want present on every endpoint but you want injected after trout has set its request headers, so e.g. you can use them in the logs.

Update our routing tests to ensure the Trout-Pattern header is set as we
expect.
It's gross and messy to have lots of middleware smushed into the Handler
method calls, with lots of paren-nesting. Give the router and each
endpoint-terminator (everywhere a Handler can be registered) the ability
to register one or more middleware functions that will wrap that
Handler. Router middleware will be called for every Handler, and called
before Handler-specific middleware.
@paddycarver paddycarver merged commit f3f48ca into main Jan 12, 2024
3 checks passed
@paddycarver paddycarver deleted the middleware branch January 12, 2024 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant