Home > Back-end >  How to change the React App localhost:3000 IP to my IP?
How to change the React App localhost:3000 IP to my IP?

Time:04-14

I am working with a paid API. They whitelisted my ip. I can fetch there data from Thunder Client and postman app. But when I'm going to fetch the data from my react app. It's nothing do anything. Basically localhost:3000 are hosted on different IP right? So how to host my react-app local host from my IP(103.124.251.85)

CodePudding user response:

To change your host for react app you just have to add HOST in your env like below:

HOST=you_system_ip

Or you can also add script in your package json file as well like below:

    "start": "HOST=you_system_ip react-scripts start",

CodePudding user response:

In your package.json you can change the "start" script to

"start": "SET HOST=103.124.251.85 && react-scripts start"

Or, you can create a file .env in the root of your project and set:

HOST=103.124.251.85

If you need to run you app over HTTPS, here is what to do:

  • In package.json you add the prestart script: it combines the private key and the crt of your SSL certificate into a pem and then it will copy it in the webpack server module.
"scripts": {
    "prestart": "type dev_certs\\cert.key dev_certs\\cert.crt > dev_certs\\server.pem && copy /y dev_certs\\server.pem node_modules\\webpack-dev-server\\ssl",
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  }
  • In the .env file you set:
PORT=443
HOST=103.124.251.85
HTTPS=true
  • Related