Skip to content
New issue

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

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

Already on GitHub? # to your account

Express * no longer works (v5.0.0-beta.3) #5910

Closed
zmatez opened this issue Sep 5, 2024 · 2 comments
Closed

Express * no longer works (v5.0.0-beta.3) #5910

zmatez opened this issue Sep 5, 2024 · 2 comments
Labels

Comments

@zmatez
Copy link

zmatez commented Sep 5, 2024

After npm updated Express to the latest version, * in requests stopped working:

        this.expressApp.get('/*', (req, res, next) => {
            console.log(req.url)
            if (req.url.startsWith("/api")) {
                next();
                return
            }
            res.sendFile(path.join(__dirname, '..', '..', 'build', 'index.html'));
        });

console.log was never logged, and I was just getting 'Cannot GET /'
or another example,

        this.expressApp.get('*',(req,res) => console.log("GET* " + req.url))
        this.expressApp.get('/',(req,res) => console.log("GET/ " + req.url))
        this.expressApp.get('',(req,res) => console.log("GET " + req.url))

only on https://url.com/ logs out GET/, else says Cannot GET ...

After downgrading to 4.19.2 it all started working, and in above example it started logging GET* on any url. Before it was Cannot GET ...

@zmatez zmatez added the bug label Sep 5, 2024
@krzysdz
Copy link
Contributor

krzysdz commented Sep 5, 2024

If by latest version you mean 5.0 beta, then that's intentional. The router dependency has been upgraded to 2.0.0-beta.1 and the changelog says:

Special * path segment behavior removed. /foo/*/bar will match a literal * as the middle segment.

You can find more details here:

4.19.2 is the latest non-beta version and is the one tagged as latest on npm. 5.0.0-beta.3 is the next version

@wesleytodd
Copy link
Member

We strongly recommend not using the beta versions. They are unstable. That said, we will be releasing the main v5 release soon and will completely be getting rid of this style of route. We are working on the release prep and docs and stuff, but you can see what we will be upgrading to with path-to-regexp@8 here https://github.com/pillarjs/path-to-regexp and pillarjs/router#117

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants