How to update React localhost (127.0.0.1:3000) to another domain (local.example.com)

随声附和 提交于 2020-01-26 03:56:06

问题


I am setting up a Localhost domain so it can communicate with this third-party API and Auth servers. For example, change 127.0.0.1 to local.example.com

local.example.com is the domain whitelisted with this third-party enterprise. I need to set this up so i can run API routes to it.

I was able to change 127.0.0.1 locally in C:\Windows\System32\drivers\etc\hosts file and now Node.js is running on it.

I added the webpack config devServer - host to local.example.com but the port is still there. I need to understand how to change this for react because right now it's porting to local.example.com:3000.


回答1:


I think you're almost there :-) The devServer option has a port property. Set that to 8080 or 80. Restart your server. Then, open the browser and try leaving it off the URL




回答2:


After digging around, I found some solutions. Essential, my goal was to set http://localhost:3000 to http://local.example.com.

1. Add local.example.com to your hosts file (windows)
2. Set up your react port to 80
This would remove the 3000 on local.example.com:3000 to local.example.com

On HTTPS request, set the port to 443
This would result to https://local.example.com


来源:https://stackoverflow.com/questions/58898600/how-to-update-react-localhost-127-0-0-13000-to-another-domain-local-example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!