简体   繁体   中英

Access site from local network. It sends requests to localhost server, but the server is on the machine, that serves the site

I am creating app. I build it with nodejs on server. It consists of several servers. My fronted sends requests to servers on localhost to fetch data from local servers ( so the urls for fetching data on the client is like localhost:3000/fetch_some). But when i want to visit the site from other computer of the local network ( i write in browser the ip of computer with fronted and servers, like 192.168.0.4:frontend_app_port ), the front side trying to fetch data from localhost of the computer i am running on, and it will not work, because there are no servers, that serves data on it. How to deal with it? Always configure front to send requests to 192.168.0.4 /(detect the computer local network ip) . Or there are some good issues for it? Does docker will be the right fit for this case?

您需要使用服务器的名称或地址,而不能通过从前端代码中引用localhost到达后端。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM