Implement Middleware in HyperExpress v7
masterMiddleware behavior in v7 follows these rules:
- Synchronous Middleware: Must explicitly call
next()to proceed. - Asynchronous Middleware: Any middleware that returns a thenable (Promise) will automatically advance the chain when the promise is fulfilled.
- Error Handling: Invoking error handling occurs if a middleware throws, rejects, calls
next(error), or fulfills with anErrorobject. - Completion Rules: Each middleware completes at most once. The first call to
next()returnstrue; subsequent calls returnfalseand do not advance the chain. Promise settlements occurring afternext()is called are ignored. - Strict Mode: You can enable the server option
strict_middleware: trueto report duplicate completion attempts to the applicable scoped error handler while still preventing double advancement.