0

I have a ReactJS web app that runs on a local network, but is also accessible via a DMZ'd address to a larger local network. The backend is a node server on that LAN, and I realized it will also have to be exposed so browsers on the broader network can get at it.

What is a good way of handling IP addresses depending on which network the user is on dynamically? Users in the LAN would have to have their browsers aimed at 192.168.x.x, say, while broader network users would have to point at 10.72.x.x, as an example, and I don't have a good idea of how to handle this on the fly.

EDIT: I can use something like ip to check my subnet and adjust accordingly, I suppose...not sure this is a best practice.

EDIT 2: I think that maybe I'm not being clear enough from the comments, so here's a little more info:

From the LAN perspective, I need the browser to hit the server at 192.168.25.31, say. And from the DMZ perspective, I need the browser to hit the server at its broader address, 10.72.10.31, for example. The two addresses are known, and static. What I need to be able to do in React is select the correct one of the two based on which subnet said browser is on.

diatrevolo
  • 2,782
  • 26
  • 45
  • Not sure why this is being voted to be closed, or why the reactjs tag was removed in an edit. It is a reactjs problem with a clear path to solution, not an open or unanswerable question. I suppose it can be argued that the problem belongs to client-side technologies in general, but may as well tag it with the one it is written in. – diatrevolo Jun 28 '19 at 15:40
  • 1
    The underlying issue relates to IP routing rather than React. The client source IP is irrelevant to React. The React site exists at a single destination IP. Clients won't hit the site unless there is an IP route to the web server from the client network. That's true if the client is on a 10., 192., or on the Internet. IP routing issues are handled at https://networkengineering.stackexchange.com, among other places. HTH – It'sNotMe Jun 28 '19 at 16:50
  • Thanks for the recommendation, appreciate the time, but this is not an IP routing question. It is a JavaScript known-IP address-handling programming question. – diatrevolo Jun 28 '19 at 16:56
  • 2
    Can you say a bit more about what you need React to do? I keyed in on "have their browsers aimed at..." which led me to believe it was an IP issue. Thx – It'sNotMe Jun 28 '19 at 17:08
  • Sure, maybe I'm not being as clear as I could be. I'll edit the question, thanks. – diatrevolo Jun 28 '19 at 17:28
  • The fact that you're using React has nothing to do with your question and the problems you're facing. – Emile Bergeron Jul 02 '19 at 14:17
  • The quickest solution would be for you to use a domain name and let the DNS deal with the IP address in the background. – Emile Bergeron Jul 02 '19 at 14:20
  • I can have a DNS reroute the request to the server from one side of the firewall, but not both. That suggestion unfortunately doesn't address the issue. I will agree that it is not a React-specific issue, it is a front-end client-side Javascript issue, so I'll give you that. I think now we're just getting into some odd semantics battle here, however, so I'm just going to leave the question be with your edit and find some other solution. – diatrevolo Jul 02 '19 at 15:59
  • You could add the `javascript` tag, but there's already [questions that address IP and port in JS](https://stackoverflow.com/q/12600244/1218980) and it's not really a viable solution to explore. It would be more productive to take a step back and consider solutions that doesn't involve JS guessing the backend IP. – Emile Bergeron Jul 02 '19 at 17:15

0 Answers0