1

I have a GET REST endpoint:

router.get('/test/*', function(req, res) {
    var test = req.originalUrl;
}

it doesn't return the full url when I have "#" sign in them:

ie:

/test/asf#23

I want "asf#23", but the above code gives me only "asf". Thoughts?

Edit: req.originalUrl, req.path, req.baseUrl, req.url all return the same thing. Any other ideas?

Edit 2: I have absolutely no control over the client, I simply need to print out the url the client tried to access. Is there a way do parse it?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574

2 Answers2

1

That's because hash part is not considered as a part of URI and so it is not passed to the server at all. You can make it URI part by requesting /test/asf?id=23 for example. In this case, you will be able to get this id by addressing req.query.id.

Sergey Lapin
  • 2,633
  • 2
  • 18
  • 20
  • thanks for sharing, but I cannot change the client's uri pattern, I just need to parse what they're trying to access, is there a way? –  Dec 29 '15 at 05:52
  • 1
    No, I'm afraid there is not. And again, this is not Express who doesn't support it, but the browser who doesn't pass it. – Sergey Lapin Dec 29 '15 at 06:17
-1

# is unsafe to be used in a url, guess that is the reason it is not being parsed

SKY
  • 240
  • 1
  • 7
  • thanks for sharing, but I cannot change the client's uri pattern, I just need to parse what they're trying to access, is there a way? I'm sure "#" isn't too uncommon in urls, express simply doesn't support it? –  Dec 29 '15 at 05:53
  • @user3586553 to answer your question, I don't think express allows you to send anchors or anchor links or urls to the server from the client. See here http://stackoverflow.com/questions/14885023/how-to-identify-an-anchor-in-a-url-in-django – SKY Dec 29 '15 at 06:21