Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the domain name on a local deployed React app

Tags:

reactjs

dns

I have a react app running on localhost port 3000 but instead of using localhost:3000 I would like to set a custom domain name to mydomain.com. I did already the change in the windows host file to

127.0.0.1 mydomain.com

but I guess I have to specify in my react app to look into this domain instead of localhost. How can I do this?

I tried : "start": "set HOST=videowall.com && set PORT=3006 && react-scripts start",

but it is returning Error: getaddrinfo ENOTFOUND videowall.com

like image 203
Ernesto Avatar asked Nov 05 '19 16:11

Ernesto


2 Answers

You need add this line to your hosts file:

  • Unix/Linux : /etc/hosts
  • Windows: C:\Windows\System32\Drivers\etc\hosts
127.0.0.1 videowall.com

NOTE: If you need access this out of your development machine like me change 127.0.0.1 to 0.0.0.0.

Use .env file in root of your React project instead of export/set envs, with this content:

HOST='videowall.com'
PORT=3006

That's it.

like image 104
Mamrezo Avatar answered Sep 28 '22 15:09

Mamrezo


Make the following change in your package.json file

"start": "HTTPS=true HOST=mycompany.com PORT=3001 react-scripts start",

like image 24
Abe Zafar Avatar answered Sep 28 '22 15:09

Abe Zafar