dimanche 25 août 2019

Node Express app.get(*) req.url is always /favion.ico

I have an Express server, where my app is served from the app.get('*') route.

I'd like to have users with promo codes visit the site from a campaign URL like so: www.mysite.com/?code=123.

The problem is every browser request is routed to the favicon request, thus my req.url and req.query variables cannot be used to get the promo codes. Req.url is always /favicon.ico and req.query is always empty.

I did find the original URL is the request object's header, but this seems like a roundabout way of achieving my objective. The request object's original URL field also points to favicon.ico.

app.get('*', (req, res) => {
  console.log(req.url);
  console.log(req.query);
}

I'd like to keep my promo code solution as quick and dirty as possible for the time being, so I'm fine with URL parameters. Is there a simple solution to extract the original URL query parameters without diving into the headers?




Aucun commentaire:

Enregistrer un commentaire