1

I start my React app using:

npm start

This starts the app on localhost:3000

I would like to have it start with a domain instead of localhost. When testing locally, I have a local domain (example mydomain.com) set to IP address 127.0.0.1. This allows me to use the actual domain in code when making requests to the backend. Without this, my code would need to support both localhost and my domain and swap them out in production.

Johann
  • 27,536
  • 39
  • 165
  • 279
  • Do you have the line : 127.0.0.1 yourdomain.com in `/etc/hosts/`? Did you try to pass something like `API_URL` from environment variables? this way you could easily have one URL to `development` and another for `production` i.e. Anyway if you navigate to your domain and is pointed to `localhost` or 127.0.0.1. you should be able to see it. What's the error here? – Adolfo Onrubia Apr 05 '20 at 08:22
  • I hope this helps. https://stackoverflow.com/questions/51146086/how-can-i-develop-locally-using-a-domain-name-instead-of-localhost3000-in-the –  Apr 05 '20 at 08:24

2 Answers2

0

npm start is only a command to run your react app in development mode.. for faster build and publish functionalities..

So for production, you will be using npm build to get a production build for the same. This won;t be automatically deplyed or hosted on your localhost:3000.

So production deployment you will have to host your compiled build files using IIS or some hosting application. There you can configure your preferred DNS, whcihever domain name you would want to use.

Barun Patro
  • 860
  • 4
  • 13
0

You can customise the url for deployment for development.

In your .env.development add this line

     HOST='mydomain.com'

If you want to deploy at https, add this line also in same file

    HTTPS=true
vineet tanwar
  • 329
  • 2
  • 9