Trouble with originalURL in Express

Hi everyone,

I’m experimenting a bit with requests and redirects within Express, and I’m new to the framework, so I might be missing something fundamental due to my newness.

In this project Glitch :・゚✧

I have the following code:

app.get("/redirect", function(request,response){
  console.log(request.originalURL);
  var fullURL = request.get("host") + "/"+ request.originalURL;
  console.log(fullURL);
  response.set('location', 'https://www.google.com');
  response.status(301).send()
});

What I would expect to happen is that request.originalURL would return /redirect, but it’s returning undefined instead.

Is there something I’m missing in order to return the original request’s full URL path?

Hi @aspires,

Its originalUrl and not originalURL! :slight_smile:

Property names are case-sensitive. However, I do understand how you’d make that mistake, acronyms in camel case are a debated topic! (Speaking from personal experience of userId vs userID)

Cheers!

3 Likes

Thank you so much! That indeed did the trick :bowing_man:

1 Like