Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

express.all('(.*)') throws error on v5 #6229

Closed
a1anw2 opened this issue Dec 17, 2024 · 3 comments
Closed

express.all('(.*)') throws error on v5 #6229

a1anw2 opened this issue Dec 17, 2024 · 3 comments
Labels

Comments

@a1anw2
Copy link

a1anw2 commented Dec 17, 2024

Using 5.0.1 and I cannot get the .all('(.*)') to work. I have followed all the examples. Dropping down to 4.x as this has drained a lot of time.

Code:

this.expressApp.all('(.*)', function (req, res, next) {
      res.set('X-Powered', 'XXX');
      next();
    });

Error:

D:\service.profile\api\node_modules\path-to-regexp\dist\index.js:123
        throw new TypeError(`Unexpected ${nextType} at ${index}, expected ${type}: ${DEBUG_URL}`);
        ^

TypeError: Unexpected ( at 1, expected END: https://git.new/pathToRegexpError
    at Iter.consume (D:\service.profile\api\node_modules\path-to-regexp\dist\index.js:123:15)
    at consume (D:\service.profile\api\node_modules\path-to-regexp\dist\index.js:179:16)
    at parse (D:\service.profile\api\node_modules\path-to-regexp\dist\index.js:183:20)
    at D:\service.profile\api\node_modules\path-to-regexp\dist\index.js:294:74
    at Array.map (<anonymous>)
    at pathToRegexp (D:\service.profile\api\node_modules\path-to-regexp\dist\index.js:294:25)
    at Object.match (D:\service.profile\api\node_modules\path-to-regexp\dist\index.js:264:30)
    at matcher (D:\service.profile\api\node_modules\router\lib\layer.js:83:23)
    at new Layer (D:\service.profile\api\node_modules\router\lib\layer.js:90:62)
    at Function.route (D:\service.profile\api\node_modules\router\index.js:421:17)

Node.js v18.14.0
@a1anw2 a1anw2 added the bug label Dec 17, 2024
@ctcpip ctcpip transferred this issue from expressjs/expressjs.com Dec 17, 2024
@ctcpip
Copy link
Member

ctcpip commented Dec 17, 2024

@a1anw2 have you seen this? https://expressjs.com/en/guide/migrating-5.html#path-syntax

@krzysdz
Copy link
Contributor

krzysdz commented Dec 17, 2024

Express 5 does not allow regular expression strings as path. '(.*)' worked in the 5.0.0-beta versions as a replacement for 4.x (*), but since 5.0.0, something like {*paramName} must be used (see #6111 (comment) and the migration guide).

In this use case, it would probably be simpler to just use .use((req, res, next) => { /*...*/ }), if you want the function to be called for all paths.

@a1anw2
Copy link
Author

a1anw2 commented Dec 17, 2024

I did look at the migration guide, but that was for specific paths, not for everything. But your @krzysdz your example there is precisely what I was looking for. THANK YOU.

@a1anw2 a1anw2 closed this as completed Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants