-
-
Notifications
You must be signed in to change notification settings - Fork 17.2k
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
Using /*splat in app.all() does not work on v5 #6111
Comments
It definitely should work. What exactly doesn't work in your case? Is the handler skipped or do you get an error? This simplified code works as expected: const express = require("express");
const app = express();
app.all("/api/*sth", (req, res, next) => {
res.setHeader("my-header", "a value");
next()
});
app.get("/*p", (req, res) => res.send("ok"));
const server = app.listen(1234, () =>
fetch("http://localhost:1234/api/random/path").then(r => {
console.log(r.headers);
server.close();
})
); |
In this case it may be easier to use app.use("/api", (req, res, next) => {
// set headers
next();
});
|
Hi @krzysdz 👋 I think I'm also encountering a similar problem. If I have a route on So for example, the file
Logs After migrating to express@5.0.1 the file looks like:
Which logs |
Good catch @Tate-CC ! I did not notice it, but the
Looks like an optional group |
Yep, what @krzysdz says is exactly the change I had to make in the PR to upgrade the I wonder if the docs for this could be improved? |
This issue happened because Express V5 introduces strict routing syntax, and the wildcard * must now be named (e.g., :splat) as a route parameter. However, simply renaming it as /api/* splat is not correct because * is no longer valid by itself. you should replace * with a named parameter using a colon (:) I think you mis-matched the : and * app.all('/api/:splat*', function (req, res, next) { |
Hi,
I recently tried to upgrade to v5 from v4 and used the following guide:
https://expressjs.com/en/guide/migrating-5.html#path-syntax
Here is my
app.all()
that sets headers on all routes:As per documentation:
I changed it to:
This does not work. Anything I am doing wrong?
The text was updated successfully, but these errors were encountered: