App.use does not alter request path for middleware
See original GitHub issueDescribe the bug
The sirv
or serve-static
middleware does not serve files when putting it under another path in the router. It does work when the mount path is /
or corresponds with the filesystem.
To Reproduce
import { App } from "@tinyhttp/app";
import serveStatic from "serve-static";
import sirv from "sirv";
new App()
.use("/static", sirv("dist/client"))
.use("/static2", serveStatic("dist/client"))
.use("/pages", sirv("dist/client"))
.listen(3000);
$ curl http://localhost:3000/static/pages/index.js
Not found
$ curl http://localhost:3000/static2/pages/index.js
Not found
$ curl http://localhost:3000/pages/index.js
console.log("hi");
Expected behavior
$ curl http://localhost:3000/static/pages/index.js
console.log("hi");
$ curl http://localhost:3000/static2/pages/index.js
console.log("hi");
$ curl http://localhost:3000/pages/index.js
Not found
Versions
node
: v14.13.0@tinyhttp/app
: ^1.0.14
Additional context
$ tree dist/client
dist/client
└── pages
├── index.js
├── index.js.map
├── outdex.js
└── outdex.js.map
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (10 by maintainers)
Top Results From Across the Web
When I change url in a middleware, it does not jump to next ...
When I change url in a middleware, it does not jump to next middleware even that middleware match pattern path · You can...
Read more >Writing middleware for use in Express apps
If myLogger is loaded after the route to the root path, the request never reaches it and the app doesn't print “LOGGED”, because...
Read more >Conditional Middleware based on request in ASP.NET Core
This post looks at how to configure ASP.NET Core middleware in a way that allows you to have different middleware for different types...
Read more >Two routers mounted at same path do not isolate their ...
Because middleware are allowed to alter the request path, method, etc., we cannot even know if the request matches a path without executing...
Read more >Complete Guide to Express Middleware - Reflectoring
When we request a non-existent route, the third error handler is invoked giving us an error message: invalid path . Using Third-Party Middleware....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@calumk looks like it’s a subapp issue. Subapp handles all the paths starting with
/
, leading to paths in the original apps getting ignoredwill close this issue and open a new one
ok so what express does is that it strips the path, e.g.
/static
, fromreq.url
andreq.path
but it remains in
req.originalUrl
will fix it in a moment 😄