Home > Mobile >  How do I change localhost:3000 to custom.domain in react
How do I change localhost:3000 to custom.domain in react

Time:01-03

 "scripts": {
    "start": "cross-env NODE_PATH=src react-scripts start",
    "build": "cross-env NODE_PATH=src react-scripts build",
  }

How do I change localhost:3000 to custom.domain in react

CodePudding user response:

You can't change localhost to mydomain.com in local development. Your react app is available in your own browser thanks to a local dev server powered by Webpack (it's made under the hood of your Create React App).

If you want a custom domain, you will need to host your code on a server. The server will have an IP address. You can then attach a custom domain name to it through any provider.

When a user tries to access your website, he will send a request to a DNS server, that will find the correct IP bound to your custom domain name and then send him back the code to display your website.

CodePudding user response:

If you want to change domain you need to upload your react app to web space. If you want to change port you need to send argument in start script.

"scripts": {
    "start": "set port=4213 && react-scripts start",
}

In this case port will be 4213. So site will run on http://localhost:4213

CodePudding user response:

You can change the port by doing the following change for the start command in your package.json file.

"scripts": {
    "start": "PORT=8050 react-scripts start",
  }

If you want to connect to a custom domain then hosting is the best option.

Other option is to first change the PORT no and then use some service like ngrok to expose that port.

  • Related