mirror of
https://github.com/expressjs/expressjs.com.git
synced 2026-02-22 03:51:33 +00:00
* Use 5.x path syntax in .all() API examples * Update examples in API docs to use Express 5 path syntax * Use an arrow function in req.route example --------- Co-authored-by: krzysdz <krzysdz@users.noreply.github.com>
1.0 KiB
1.0 KiB
router.all(path, [callback, ...] callback)
This method is just like the router.METHOD() methods, except that it matches all HTTP methods (verbs).
This method is extremely useful for
mapping "global" logic for specific path prefixes or arbitrary matches.
For example, if you placed the following route at the top of all other
route definitions, it would require that all routes from that point on
would require authentication, and automatically load a user. Keep in mind
that these callbacks do not have to act as end points; loadUser
can perform a task, then call next() to continue matching subsequent
routes.
router.all('{*splat}', requireAuthentication, loadUser)
Or the equivalent:
router.all('{*splat}', requireAuthentication)
router.all('{*splat}', loadUser)
Another example of this is white-listed "global" functionality. Here, the example is much like before, but it only restricts paths prefixed with "/api":
router.all('/api/{*splat}', requireAuthentication)