Get full route path #6767
Unanswered
marcellino-ornelas
asked this question in
Q&A
Replies: 1 comment 2 replies
-
Have you tried const express = require("express");
const app = express();
const router = express.Router();
router.get('/my/path', (req,res) => {
console.log(req.originalUrl); // '/api/my/path'
console.log(req.url); // '/my/path'
console.log(req.baseUrl); // '/api'
console.log(req.path); // '/my/path'
res.send("ok");
});
app.use("/api", router);
const server = app.listen(8080, async () => {
await fetch("http://127.0.0.1:8080/api/my/path");
server.close();
}); |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello quick question, is it possible to get the full route path?
example app:
Now when someone calls
/api/my/path
, is there a way to get this full route path fromreq
?currently im using
req.route.path
but since this is a child router, it only returning'/my/path
and not/api/my/path
.Edited:
req.originalUrl
doesn't work for me because it doesn't return the parametrized version when urls takes params see commentMaybe related topic?: #5961
Beta Was this translation helpful? Give feedback.
All reactions