Ernesto
Ernesto

Reputation: 173

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

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

Upvotes: 8

Views: 39758

Answers (5)

GMKHussain
GMKHussain

Reputation: 4661

Add following link in your host file

Windows: C:\Windows\System32\Drivers\etc\hosts

Linux: /etc/hosts

127.0.0.1 mydomain.local
127.0.0.1 subdomain.mydomain.local

Add HOST in .env file

// ..
HOST=mydomain.local
// ..

Run React App

npm run start

Visit: mydomain.local

Upvotes: 1

Abe Zafar
Abe Zafar

Reputation: 51

Make the following change in your package.json file

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

Upvotes: 5

Mamrezo
Mamrezo

Reputation: 1489

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.

Upvotes: 18

Ricardo Gonzalez
Ricardo Gonzalez

Reputation: 1879

If you are using webpack there is a property in devServer that is called host, you can change the hostname of the app there.

Upvotes: 0

Julian Kleine
Julian Kleine

Reputation: 1547

In general create-react-app does assume it is hosted at the server root. If you would like to modify this behaviour, please refer to the create react app documentation for relative paths. You can specify it in your package.json under homepage.

"homepage": "http://mywebsite.com/relativepath",

As of your description of the error I suggest that modifying your host file should be fine. You should check that the domain locally resolves to the correct IP.

On mac/unix try traceroute mydomain.com On windows try tracert mydomain.com

Upvotes: 1

Related Questions