From 9fc12855c4515928844c2e2f77b5d14d6dbb956a Mon Sep 17 00:00:00 2001 From: vibhor-aggr <108814060+vibhor-aggr@users.noreply.github.com> Date: Sat, 11 Jul 2026 19:39:41 +0530 Subject: [PATCH 1/3] docs: clarify route path matching --- src/content/api/4x/api/application/index.mdx | 55 ++++++++++++-------- src/content/api/5x/api/application/index.mdx | 55 ++++++++++++-------- 2 files changed, 66 insertions(+), 44 deletions(-) diff --git a/src/content/api/4x/api/application/index.mdx b/src/content/api/4x/api/application/index.mdx index bc075745a6..15aa4b7742 100644 --- a/src/content/api/4x/api/application/index.mdx +++ b/src/content/api/4x/api/application/index.mdx @@ -264,9 +264,10 @@ 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 for which the route callback 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. Route paths match complete request paths; for syntax examples, see [Path + examples](#path-examples). Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -337,9 +338,10 @@ 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 for which the route callback 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. Route paths match complete request paths; for syntax examples, see [Path + examples](#path-examples). Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -568,9 +570,10 @@ 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 for which the route callback 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. Route paths match complete request paths; for syntax examples, see [Path + examples](#path-examples). Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -719,9 +722,10 @@ 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 for which the route callback 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. Route paths match complete request paths; for syntax examples, see [Path + examples](#path-examples). Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -741,6 +745,10 @@ 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. +Route paths match the complete request path for a route. Unlike [app.use()](#appuse), a route path +does not match path prefixes by default. For example, `app.get('/apple', ...)` matches "/apple" but +not "/apple/images" unless the path pattern is written to match that longer path. + #### Routing methods Express supports the following routing methods corresponding to the HTTP methods of the same names: @@ -830,9 +838,10 @@ 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 for which the route callback 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. Route paths match complete request paths; for syntax examples, see [Path + examples](#path-examples). Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -1203,9 +1212,10 @@ 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 for which the route callback 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. Route paths match complete request paths; for syntax examples, see [Path + examples](#path-examples). Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -1245,9 +1255,10 @@ 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 for which the route callback 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. Route paths match complete request paths; for syntax examples, see [Path + examples](#path-examples). Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -1651,7 +1662,7 @@ 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 "`/`". +Middleware mounted with `app.use()` 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. diff --git a/src/content/api/5x/api/application/index.mdx b/src/content/api/5x/api/application/index.mdx index fcbb181455..1d2ce99f3f 100644 --- a/src/content/api/5x/api/application/index.mdx +++ b/src/content/api/5x/api/application/index.mdx @@ -312,9 +312,10 @@ 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 for which the route callback 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. Route paths match complete request paths; for syntax examples, see [Path + examples](#path-examples). Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -385,9 +386,10 @@ 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 for which the route callback 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. Route paths match complete request paths; for syntax examples, see [Path + examples](#path-examples). Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -593,9 +595,10 @@ 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 for which the route callback 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. Route paths match complete request paths; for syntax examples, see [Path + examples](#path-examples). Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -763,9 +766,10 @@ 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 for which the route callback 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. Route paths match complete request paths; for syntax examples, see [Path + examples](#path-examples). Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -785,6 +789,10 @@ 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. +Route paths match the complete request path for a route. Unlike [app.use()](#appuse), a route path +does not match path prefixes by default. For example, `app.get('/apple', ...)` matches "/apple" but +not "/apple/images" unless the path pattern is written to match that longer path. + #### Routing methods Express supports the following routing methods corresponding to the HTTP methods of the same names: @@ -1041,9 +1049,10 @@ 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 for which the route callback 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. Route paths match complete request paths; for syntax examples, see [Path + examples](#path-examples). Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -1083,9 +1092,10 @@ 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 for which the route callback 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. Route paths match complete request paths; for syntax examples, see [Path + examples](#path-examples). Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -1124,9 +1134,10 @@ 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 for which the route callback 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. Route paths match complete request paths; for syntax examples, see [Path + examples](#path-examples). Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -1560,7 +1571,7 @@ 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 "`/`". +Middleware mounted with `app.use()` 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. From f83f83a74a363586536c8a75f4ffb7c8123199a9 Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Sat, 24 Oct 2026 14:29:19 -0500 Subject: [PATCH 2/3] docs: clarify regular expression route matching --- src/content/api/4x/api/application/index.mdx | 34 +++++++++++--------- src/content/api/5x/api/application/index.mdx | 34 +++++++++++--------- 2 files changed, 38 insertions(+), 30 deletions(-) diff --git a/src/content/api/4x/api/application/index.mdx b/src/content/api/4x/api/application/index.mdx index 15aa4b7742..2bfaf90c86 100644 --- a/src/content/api/4x/api/application/index.mdx +++ b/src/content/api/4x/api/application/index.mdx @@ -266,8 +266,8 @@ app.use('/admin', admin); The path for which the route callback 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. Route paths match complete request paths; for syntax examples, see [Path - examples](#path-examples). + any of the above. String route paths match complete request paths; for syntax examples, see + [Path examples](#path-examples). Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -340,8 +340,8 @@ app.all('/api/*', requireAuthentication); The path for which the route callback 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. Route paths match complete request paths; for syntax examples, see [Path - examples](#path-examples). + any of the above. String route paths match complete request paths; for syntax examples, see + [Path examples](#path-examples). Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -572,8 +572,8 @@ app.get('title'); The path for which the route callback 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. Route paths match complete request paths; for syntax examples, see [Path - examples](#path-examples). + any of the above. String route paths match complete request paths; for syntax examples, see + [Path examples](#path-examples). Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -724,8 +724,8 @@ All the forms of Node's [http.Server.listen()](https://nodejs.org/api/http.html# The path for which the route callback 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. Route paths match complete request paths; for syntax examples, see [Path - examples](#path-examples). + any of the above. String route paths match complete request paths; for syntax examples, see + [Path examples](#path-examples). Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -745,10 +745,14 @@ 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. -Route paths match the complete request path for a route. Unlike [app.use()](#appuse), a route path +String route paths match the complete request path. Unlike [app.use()](#appuse), a string route path does not match path prefixes by default. For example, `app.get('/apple', ...)` matches "/apple" but not "/apple/images" unless the path pattern is written to match that longer path. +Regular expression route paths follow the expression's own matching rules. For example, +`app.get(/apple/, ...)` also matches "/apple/images". Use `^` and `$` to require a complete match, +as in `app.get(/^\/apple$/, ...)`. + #### Routing methods Express supports the following routing methods corresponding to the HTTP methods of the same names: @@ -840,8 +844,8 @@ For more information on routing, see the [routing guide](/guide/routing/). The path for which the route callback 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. Route paths match complete request paths; for syntax examples, see [Path - examples](#path-examples). + any of the above. String route paths match complete request paths; for syntax examples, see + [Path examples](#path-examples). Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -1214,8 +1218,8 @@ it is usually better to use [req.baseUrl](/api/request/#reqbaseurl) to get the c The path for which the route callback 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. Route paths match complete request paths; for syntax examples, see [Path - examples](#path-examples). + any of the above. String route paths match complete request paths; for syntax examples, see + [Path examples](#path-examples). Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -1257,8 +1261,8 @@ app.post('/', function (req: Request, res: Response) { The path for which the route callback 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. Route paths match complete request paths; for syntax examples, see [Path - examples](#path-examples). + any of the above. String route paths match complete request paths; for syntax examples, see + [Path examples](#path-examples). Callback functions; can be: a middleware function, a series of middleware functions (separated diff --git a/src/content/api/5x/api/application/index.mdx b/src/content/api/5x/api/application/index.mdx index 1d2ce99f3f..ed76c24188 100644 --- a/src/content/api/5x/api/application/index.mdx +++ b/src/content/api/5x/api/application/index.mdx @@ -314,8 +314,8 @@ app.use('/admin', admin); The path for which the route callback 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. Route paths match complete request paths; for syntax examples, see [Path - examples](#path-examples). + any of the above. String route paths match complete request paths; for syntax examples, see + [Path examples](#path-examples). Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -388,8 +388,8 @@ app.all('/api/{*splat}', requireAuthentication); The path for which the route callback 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. Route paths match complete request paths; for syntax examples, see [Path - examples](#path-examples). + any of the above. String route paths match complete request paths; for syntax examples, see + [Path examples](#path-examples). Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -597,8 +597,8 @@ app.get('title'); The path for which the route callback 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. Route paths match complete request paths; for syntax examples, see [Path - examples](#path-examples). + any of the above. String route paths match complete request paths; for syntax examples, see + [Path examples](#path-examples). Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -768,8 +768,8 @@ actually supported. The path for which the route callback 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. Route paths match complete request paths; for syntax examples, see [Path - examples](#path-examples). + any of the above. String route paths match complete request paths; for syntax examples, see + [Path examples](#path-examples). Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -789,10 +789,14 @@ 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. -Route paths match the complete request path for a route. Unlike [app.use()](#appuse), a route path +String route paths match the complete request path. Unlike [app.use()](#appuse), a string route path does not match path prefixes by default. For example, `app.get('/apple', ...)` matches "/apple" but not "/apple/images" unless the path pattern is written to match that longer path. +Regular expression route paths follow the expression's own matching rules. For example, +`app.get(/apple/, ...)` also matches "/apple/images". Use `^` and `$` to require a complete match, +as in `app.get(/^\/apple$/, ...)`. + #### Routing methods Express supports the following routing methods corresponding to the HTTP methods of the same names: @@ -1051,8 +1055,8 @@ it is usually better to use [req.baseUrl](/api/request/#reqbaseurl) to get the c The path for which the route callback 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. Route paths match complete request paths; for syntax examples, see [Path - examples](#path-examples). + any of the above. String route paths match complete request paths; for syntax examples, see + [Path examples](#path-examples). Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -1094,8 +1098,8 @@ app.post('/', (req: Request, res: Response) => { The path for which the route callback 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. Route paths match complete request paths; for syntax examples, see [Path - examples](#path-examples). + any of the above. String route paths match complete request paths; for syntax examples, see + [Path examples](#path-examples). Callback functions; can be: a middleware function, a series of middleware functions (separated @@ -1136,8 +1140,8 @@ app.put('/', (req: Request, res: Response) => { The path for which the route callback 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. Route paths match complete request paths; for syntax examples, see [Path - examples](#path-examples). + any of the above. String route paths match complete request paths; for syntax examples, see + [Path examples](#path-examples). Callback functions; can be: a middleware function, a series of middleware functions (separated From 93a73b9a31c964cb34dbdcbcaefe5d6892b9c6b3 Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Sat, 24 Oct 2026 14:34:08 -0500 Subject: [PATCH 3/3] docs: simplify route matching explanations --- src/content/api/4x/api/application/index.mdx | 58 +++++++------------- src/content/api/5x/api/application/index.mdx | 58 +++++++------------- 2 files changed, 42 insertions(+), 74 deletions(-) diff --git a/src/content/api/4x/api/application/index.mdx b/src/content/api/4x/api/application/index.mdx index 2bfaf90c86..ceb66b0d03 100644 --- a/src/content/api/4x/api/application/index.mdx +++ b/src/content/api/4x/api/application/index.mdx @@ -264,10 +264,8 @@ app.use('/admin', admin); - The path for which the route callback 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. String route paths match complete request paths; for syntax 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 @@ -338,10 +336,8 @@ app.all('/api/*', requireAuthentication); - The path for which the route callback 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. String route paths match complete request paths; for syntax 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 @@ -570,10 +566,8 @@ app.get('title'); - The path for which the route callback 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. String route paths match complete request paths; for syntax 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 @@ -722,10 +716,8 @@ All the forms of Node's [http.Server.listen()](https://nodejs.org/api/http.html# - The path for which the route callback 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. String route paths match complete request paths; for syntax 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 @@ -745,13 +737,11 @@ 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 paths match the complete request path. Unlike [app.use()](#appuse), a string route path -does not match path prefixes by default. For example, `app.get('/apple', ...)` matches "/apple" but -not "/apple/images" unless the path pattern is written to match that longer path. +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 expression route paths follow the expression's own matching rules. For example, -`app.get(/apple/, ...)` also matches "/apple/images". Use `^` and `$` to require a complete match, -as in `app.get(/^\/apple$/, ...)`. +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 @@ -842,10 +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 route callback 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. String route paths match complete request paths; for syntax 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 @@ -1216,10 +1204,8 @@ it is usually better to use [req.baseUrl](/api/request/#reqbaseurl) to get the c - The path for which the route callback 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. String route paths match complete request paths; for syntax 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 @@ -1259,10 +1245,8 @@ app.post('/', function (req: Request, res: Response) { - The path for which the route callback 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. String route paths match complete request paths; for syntax 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 @@ -1666,9 +1650,9 @@ the middleware function is executed when the base of the requested path matches #### Description -Middleware mounted with `app.use()` 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 ed76c24188..7400945529 100644 --- a/src/content/api/5x/api/application/index.mdx +++ b/src/content/api/5x/api/application/index.mdx @@ -312,10 +312,8 @@ app.use('/admin', admin); - The path for which the route callback 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. String route paths match complete request paths; for syntax 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 @@ -386,10 +384,8 @@ app.all('/api/{*splat}', requireAuthentication); - The path for which the route callback 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. String route paths match complete request paths; for syntax 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 @@ -595,10 +591,8 @@ app.get('title'); - The path for which the route callback 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. String route paths match complete request paths; for syntax 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 @@ -766,10 +760,8 @@ actually supported. - The path for which the route callback 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. String route paths match complete request paths; for syntax 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 @@ -789,13 +781,11 @@ 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 paths match the complete request path. Unlike [app.use()](#appuse), a string route path -does not match path prefixes by default. For example, `app.get('/apple', ...)` matches "/apple" but -not "/apple/images" unless the path pattern is written to match that longer path. +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 expression route paths follow the expression's own matching rules. For example, -`app.get(/apple/, ...)` also matches "/apple/images". Use `^` and `$` to require a complete match, -as in `app.get(/^\/apple$/, ...)`. +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 @@ -1053,10 +1043,8 @@ it is usually better to use [req.baseUrl](/api/request/#reqbaseurl) to get the c - The path for which the route callback 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. String route paths match complete request paths; for syntax 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 @@ -1096,10 +1084,8 @@ app.post('/', (req: Request, res: Response) => { - The path for which the route callback 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. String route paths match complete request paths; for syntax 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 @@ -1138,10 +1124,8 @@ app.put('/', (req: Request, res: Response) => { =20.19.3 <21 || >=22.2.0' }}> - The path for which the route callback 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. String route paths match complete request paths; for syntax 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 @@ -1575,9 +1559,9 @@ the middleware function is executed when the base of the requested path matches #### Description -Middleware mounted with `app.use()` 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: