Lesson 7.1

The onion and the dispatcher

What middleware is, how next() advances the stack, and how a response can stop dispatch. Then you build the dispatcher that awaits every entry.

32 minsrc/pipeline.js
  • Define middleware as a function of (req, res, next) with three moves, and read the onion's in-phase and out-phase order.
  • Explain why dispatch advances only when an entry calls next(), and how omitting next() stops downstream work.
  • Build dispatch(stack, req, res) - index recursion, the double-next guard, downstream tracking, and Promise.try.
Locked

This chapter is part of the framework capstone. Chapters 1 and 2 are free to build - unlock the rest to keep going.

Unlock the depth