0

I am using express and need to get the information in the querystring of the page i'm loading in any request for static files, be it marked in the html like or by ajax requests.

I'm loading the page like this: http://localhost:8080/?qstringValue=someValue

when i receive requests in the server for static files like images or favico, from that page, is there a way to get what's in the query string of the url i'm loading?

i will have several pages running: http://localhost:8080 only diferentiated by the query string and i will need to know where the request for images is coming from based on the different query strings

The solution may be on the express server(node-http) or in the frontend.

Thanks in advance

André Alçada Padez
  • 10,987
  • 24
  • 67
  • 120
  • 3
    this is already answered here [link][1] [1]: http://stackoverflow.com/questions/6912584/how-to-get-get-query-string-variables-in-express-js-on-node-js – prasun Sep 24 '15 at 13:49
  • I think we just need to check request env ex, `req.env` usually we write in a function. – Mathew P. Jones Feb 17 '22 at 00:09

1 Answers1

0
app.get('/', function(req, res){
  res.writeHead(200, {'content-type': 'text/plain'});
  res.write('query: ' + req.qStringValue + '\n');
  queryStuff = JSON.stringify(req.query);
  res.end('That\'s all folks'  + '\n' + queryStuff);
});

This has already been answered before as well here

Community
  • 1
  • 1
prasun
  • 7,073
  • 9
  • 41
  • 59
  • this is not the answer to my question. What i need is, after serving the page, every request that comes from that page i need to know what is in that querystring – André Alçada Padez Sep 24 '15 at 16:10
  • you will need to monitor that on individual/wildcard/regex routes handler. Additionally, you can set a unique cookie on the client in the response so, that you can track that the query string points to the specific page response. – prasun Sep 24 '15 at 16:19
  • thing is, i will have several pages running: http://localhost:8080 only diferentiated by the query string and i will need to know where the request for images is coming from based on the different query strings – André Alçada Padez Sep 24 '15 at 16:24
  • if those pages are on single machine, you can return a unique value for a JS Script on client side, and then you can pass that value back to server an then make analogy on server based on the incoming value in the request param/header – prasun Sep 24 '15 at 16:46