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

feat!: integrate router with app and app.fetch #822

Merged
merged 11 commits into from
Jul 11, 2024
Merged

feat!: integrate router with app and app.fetch #822

merged 11 commits into from
Jul 11, 2024

Conversation

pi0
Copy link
Member

@pi0 pi0 commented Jul 9, 2024

This is a major upgrade for h3! Since the initial version, h3's core was modeled as a stack runner, using an array of middleware (path prefixes and event handlers) matching them one by one, and stopping as soon as the first middleware responded.

We then added a new router system to h3 using radix3 which uses route pattern matching.

With advancements of rou3, we can actually have a much smarter combined app.

In order to keep compatibility with previous versions, the h3 app smartly chooses between 3 strategies (in order):

  1. global middleware without prefix registered with app.use(handler)
  2. middleware with route registered with app.use("/prefix", {}) (this is not encouraged due to perf overhead!)
  3. routes with method registered with app.all(handler or app.[method](handler)

Any of the middleware can still return a response to stop the process (this is to keep more backward compatibility) but there are new behavior changes:

  • middleware registered with app.use("/path", handler) only match /path route. For matching all subpaths like before, it should be updated to app.use("/path/**", handler)
  • The event.path received in each handler will have a full path without omitting the prefixes. useBase(base, handler) wrapper can be used if old behavior is desired.
  • custom match function for app.use is not supported anymore (middleware can skip themselves based on path)

Other changers:

  • app.options (to access config) is renamed to app.config (app.options registers an event handler for OPTIONS HTTP method)

Migration guide: #787

@pi0 pi0 self-assigned this Jul 9, 2024
@pi0 pi0 mentioned this pull request Jul 10, 2024
1 task
@pi0 pi0 changed the title feat!: integrate router with app feat!: integrate router with app and app.fetch Jul 11, 2024
@pi0 pi0 marked this pull request as ready for review July 11, 2024 11:37
@pi0 pi0 merged commit da7d480 into main Jul 11, 2024
3 checks passed
@pi0 pi0 deleted the feat/app-router branch July 11, 2024 11:39
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.

1 participant