Thursday 16 February 2017

[Express] How do I determine where my request is coming from?

Quick question,I currently have a node.js application that takes parameters via a URL and returns a .wav file via res.redirect(mywavfile) which then redirects to my .wav file. I then have a webpage which speaks to this server to play the requested .wav file like so: audio.src = "http://ift.tt/2lWVzp4" + encodeURIComponent(message);"This works perfectly and returns the .wav file as requested and plays it in the browser. However, I would really like to make it so I can create a quick API which returns the file location as a string. For this I would need to use res.send(file location). But how can I differentiate between the user on my webpage making a request to my server which serves the .wav files and somebody requesting it via something like Postman?Is there an easy way to let the user trying to access the files decide if it would like a res.redirect or a string res.send response?

Submitted February 16, 2017 at 04:57PM by haybros

No comments:

Post a Comment