3

I have a simple node http server set up currently, I'm trying to build the server so that it only accepts post requests from certain domains. I'm trying to get the domain of the server that made a post request to my node server but can't quite figure it out.

In my test environment, I am making the post request from localhost:3000 to my node server which is running on localhost:9220. I have been examining the req object but can't seem to find localhost:3000 mentioned anywhere in it.

http.createServer(function (req, res) {
    if(req.method == 'POST')
      {
         // Here is where I want to find the domain of the server 
         // making the request
      {
}).listen(9220);

It's probably simple but I am having trouble

thanks for the help!

1 Answer 1

4

There is no way to do this reliably.

If you make a cross-origin Ajax request, a browser will add an Origin header to it. If you submit a form, a browser might add a Referer header to it.

Sign up to request clarification or add additional context in comments.

1 Comment

Okay, that makes sense, I feel like it would have been a more obvious solution if it was doable. Thanks for your response!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.