-
FinalHandler
(see expressjs/finalhandler) Acts as the final middleware in the application. If no "next" handler is pased tohandle
, this is invoked whennext()
is called, and no more items remain in the stack. Will either return a 404 (no error) or a 500 (if an error was passed tonext()
). -
Route
(see connect's proto.js, in theuse
definition). Encapsulates a route and a handle, and is what the stack inside the app consists of.- Interestingly, the way "sub apps" (i.e., middleware handlers) are treated is that they get cast to a callable that calls their own
handle
method, and their "route" property is set to the given route. Not sure the latter is necessary, as it will be in the request.
- Interestingly, the way "sub apps" (i.e., middleware handlers) are treated is that they get cast to a callable that calls their own
-
Dispatcher
(connect'scall
); accepts handle, route, err, req, res, and next.- Determines if arity of handler and whether or not an error is presen, and uses those to determine whether to call as an error handler or as a regular handler. If arity/error mismatch, nothing is called.
- Does calling in a try/catch; if an error is caught, it is passed as the argument to
next()
.
-
handle()
definesdone
andnext
, and then callsnext()
. -
next()
is a closure defined in thehandle()
logic. It pulls a handler off the stack; if none is present, it calls either the "next" (calledout
in connect) passed tohandle
, or the final handler. If a route is present on the handler, it checks to see if the current URL in the request matches. If not, it calls itself. If it does match, it munges the request URL to strip off the part matching, and also places the "removed" segment in the URL. -
Potentially a
Server
. This would take an incoming request, pass it to the app/middleware, and likely be responsible for emitting the response at the end. -
HTTP objects
- Request
- Ability to retrieve URL
- Ability to retrieve method
- Ability to retrieve headers
- Ability to retrieve body
- Ability to store arbitrary properties; retrieving unknown properties should return null values.
- Response
- Ability to set status code
- Ability to set headers
- Ability to set/append body
-
end()
to indicate it should be sent- Only allow calling
end()
once
- Only allow calling
- Request
- Matching the "route" of a handler is done in a case-insensitive manner. I.e., if you call
use('/Api', handler)
, the application checks against/api
. - Only match the handler route if it borders a
/
,.
, or the end of the path. - Once matched, trim the matched part off, and store anything remaininginto the request URL, ensuring a leading slash. Store the original URL in an "originalUrl" property of the request (but only the very first time).