diff --git a/src/content/api/4x/api/application/index.mdx b/src/content/api/4x/api/application/index.mdx index bc075745a6..ceb66b0d03 100644 --- a/src/content/api/4x/api/application/index.mdx +++ b/src/content/api/4x/api/application/index.mdx @@ -264,9 +264,8 @@ app.use('/admin', admin); - The path for which the middleware function is invoked; can be any of: a string representing a - path, a path pattern, a regular expression pattern to match paths, or an array of combinations - of any of the above. For examples, see [Path examples](#path-examples). + The path to match for this route: a string, a regular expression, or an array of either. + String patterns match the whole request path. See [Path examples](#path-examples) for syntax. Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -337,9 +336,8 @@ app.all('/api/*', requireAuthentication); - The path for which the middleware function is invoked; can be any of: a string representing a - path, a path pattern, a regular expression pattern to match paths, or an array of combinations - of any of the above. For examples, see [Path examples](#path-examples). + The path to match for this route: a string, a regular expression, or an array of either. + String patterns match the whole request path. See [Path examples](#path-examples) for syntax. Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -568,9 +566,8 @@ app.get('title'); - The path for which the middleware function is invoked; can be any of: a string representing a - path, a path pattern, a regular expression pattern to match paths, or an array of combinations - of any of the above. For examples, see [Path examples](#path-examples). + The path to match for this route: a string, a regular expression, or an array of either. + String patterns match the whole request path. See [Path examples](#path-examples) for syntax. Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -719,9 +716,8 @@ All the forms of Node's [http.Server.listen()](https://nodejs.org/api/http.html# - The path for which the middleware function is invoked; can be any of: a string representing a - path, a path pattern, a regular expression pattern to match paths, or an array of combinations - of any of the above. For examples, see [Path examples](#path-examples). + The path to match for this route: a string, a regular expression, or an array of either. + String patterns match the whole request path. See [Path examples](#path-examples) for syntax. Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -741,6 +737,12 @@ Routes an HTTP request, where METHOD is the HTTP method of the request, such as PUT, POST, and so on, in lowercase. Thus, the actual methods are `app.get()`, `app.post()`, `app.put()`, and so on. See [Routing methods](#routing-methods) below for the complete list. +String route patterns match the whole request path. For example, `app.get('/apple', ...)` matches +`/apple`, but not `/apple/images`. With the same path, [app.use()](#appuse) matches both. + +Regular expressions can match part of the path. `app.get(/apple/, ...)` matches `/apple/images`. +Use `^` and `$` for a full match: `app.get(/^\/apple$/, ...)` matches only `/apple`. + #### Routing methods Express supports the following routing methods corresponding to the HTTP methods of the same names: @@ -830,9 +832,8 @@ For more information on routing, see the [routing guide](/guide/routing/). =20.19.3 <21 || >=22.2.0' }}> - The path for which the middleware function is invoked; can be any of: a string representing a - path, a path pattern, a regular expression pattern to match paths, or an array of combinations - of any of the above. For examples, see [Path examples](#path-examples). + The path to match for this route: a string, a regular expression, or an array of either. + String patterns match the whole request path. See [Path examples](#path-examples) for syntax. Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -1203,9 +1204,8 @@ it is usually better to use [req.baseUrl](/api/request/#reqbaseurl) to get the c - The path for which the middleware function is invoked; can be any of: a string representing a - path, a path pattern, a regular expression pattern to match paths, or an array of combinations - of any of the above. For examples, see [Path examples](#path-examples). + The path to match for this route: a string, a regular expression, or an array of either. + String patterns match the whole request path. See [Path examples](#path-examples) for syntax. Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -1245,9 +1245,8 @@ app.post('/', function (req: Request, res: Response) { - The path for which the middleware function is invoked; can be any of: a string representing a - path, a path pattern, a regular expression pattern to match paths, or an array of combinations - of any of the above. For examples, see [Path examples](#path-examples). + The path to match for this route: a string, a regular expression, or an array of either. + String patterns match the whole request path. See [Path examples](#path-examples) for syntax. Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -1651,9 +1650,9 @@ the middleware function is executed when the base of the requested path matches #### Description -A route will match any path that follows its path immediately with a "`/`". -For example: `app.use('/apple', ...)` will match "/apple", "/apple/images", -"/apple/images/news", and so on. +With a string path, `app.use()` matches that path and its subpaths. For example, +`app.use('/apple', ...)` matches `/apple`, `/apple/images`, and `/apple/images/news`, +but not `/apples`. Since `path` defaults to "/", middleware mounted without a path will be executed for every request to the app. For example, this middleware function will be executed for _every_ request to the app: diff --git a/src/content/api/5x/api/application/index.mdx b/src/content/api/5x/api/application/index.mdx index fcbb181455..7400945529 100644 --- a/src/content/api/5x/api/application/index.mdx +++ b/src/content/api/5x/api/application/index.mdx @@ -312,9 +312,8 @@ app.use('/admin', admin); - The path for which the middleware function is invoked; can be any of: a string representing a - path, a path pattern, a regular expression pattern to match paths, or an array of combinations - of any of the above. For examples, see [Path examples](#path-examples). + The path to match for this route: a string, a regular expression, or an array of either. + String patterns match the whole request path. See [Path examples](#path-examples) for syntax. Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -385,9 +384,8 @@ app.all('/api/{*splat}', requireAuthentication); - The path for which the middleware function is invoked; can be any of: a string representing a - path, a path pattern, a regular expression pattern to match paths, or an array of combinations - of any of the above. For examples, see [Path examples](#path-examples). + The path to match for this route: a string, a regular expression, or an array of either. + String patterns match the whole request path. See [Path examples](#path-examples) for syntax. Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -593,9 +591,8 @@ app.get('title'); - The path for which the middleware function is invoked; can be any of: a string representing a - path, a path pattern, a regular expression pattern to match paths, or an array of combinations - of any of the above. For examples, see [Path examples](#path-examples). + The path to match for this route: a string, a regular expression, or an array of either. + String patterns match the whole request path. See [Path examples](#path-examples) for syntax. Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -763,9 +760,8 @@ actually supported. - The path for which the middleware function is invoked; can be any of: a string representing a - path, a path pattern, a regular expression pattern to match paths, or an array of combinations - of any of the above. For examples, see [Path examples](#path-examples). + The path to match for this route: a string, a regular expression, or an array of either. + String patterns match the whole request path. See [Path examples](#path-examples) for syntax. Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -785,6 +781,12 @@ Routes an HTTP request, where METHOD is the HTTP method of the request, such as PUT, POST, and so on, in lowercase. Thus, the actual methods are `app.get()`, `app.post()`, `app.put()`, and so on. See [Routing methods](#routing-methods) below for the complete list. +String route patterns match the whole request path. For example, `app.get('/apple', ...)` matches +`/apple`, but not `/apple/images`. With the same path, [app.use()](#appuse) matches both. + +Regular expressions can match part of the path. `app.get(/apple/, ...)` matches `/apple/images`. +Use `^` and `$` for a full match: `app.get(/^\/apple$/, ...)` matches only `/apple`. + #### Routing methods Express supports the following routing methods corresponding to the HTTP methods of the same names: @@ -1041,9 +1043,8 @@ it is usually better to use [req.baseUrl](/api/request/#reqbaseurl) to get the c - The path for which the middleware function is invoked; can be any of: a string representing a - path, a path pattern, a regular expression pattern to match paths, or an array of combinations - of any of the above. For examples, see [Path examples](#path-examples). + The path to match for this route: a string, a regular expression, or an array of either. + String patterns match the whole request path. See [Path examples](#path-examples) for syntax. Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -1083,9 +1084,8 @@ app.post('/', (req: Request, res: Response) => { - The path for which the middleware function is invoked; can be any of: a string representing a - path, a path pattern, a regular expression pattern to match paths, or an array of combinations - of any of the above. For examples, see [Path examples](#path-examples). + The path to match for this route: a string, a regular expression, or an array of either. + String patterns match the whole request path. See [Path examples](#path-examples) for syntax. Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -1124,9 +1124,8 @@ app.put('/', (req: Request, res: Response) => { =20.19.3 <21 || >=22.2.0' }}> - The path for which the middleware function is invoked; can be any of: a string representing a - path, a path pattern, a regular expression pattern to match paths, or an array of combinations - of any of the above. For examples, see [Path examples](#path-examples). + The path to match for this route: a string, a regular expression, or an array of either. + String patterns match the whole request path. See [Path examples](#path-examples) for syntax. Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -1560,9 +1559,9 @@ the middleware function is executed when the base of the requested path matches #### Description -A route will match any path that follows its path immediately with a "`/`". -For example: `app.use('/apple', ...)` will match "/apple", "/apple/images", -"/apple/images/news", and so on. +With a string path, `app.use()` matches that path and its subpaths. For example, +`app.use('/apple', ...)` matches `/apple`, `/apple/images`, and `/apple/images/news`, +but not `/apples`. Since `path` defaults to "/", middleware mounted without a path will be executed for every request to the app. For example, this middleware function will be executed for _every_ request to the app: