How to open a create-react-app from another computer connected to the same network?

前端 未结 10 558
旧时难觅i
旧时难觅i 2021-02-02 06:38

I am using create-react-app and hosting in its default port localhost:3000 and want to access this from another device on the same net

相关标签:
10条回答
  • 2021-02-02 07:17

    If you are on Ubuntu, simply run

    $> sudo ufw allow 3000
    

    Then access your app using your internal ip from local network. to get your local IP run:

    $> ifconfig
    
    0 讨论(0)
  • 2021-02-02 07:19

    My react-scripts:3.4.1 is working,

    from

    "scripts": {
      "start": "react-scripts start"
    }
    

    to ( 0.0.0.0 is not work )

    "scripts": {
      "start": "HOST=127.0.0.1 react-scripts start"
    }
    
    0 讨论(0)
  • 2021-02-02 07:21

    If you are on windows and the above solutions don't work, it is most probably a firewall issue. You can try looking in Allowed Applications in Control Panel, to check if node is allowed on private networks. Or looking in the Windows Defender Firewall with Advanced Security and checking the Monitoring\Firewall tab and check for Node.js.

    0 讨论(0)
  • 2021-02-02 07:24

    Simply run HOST=0.0.0.0 npm run start.
    Afterwards open the url from another device on the network.

    In your case, 192.168.0.5:3000 would work.

    Documentation for setting HOST environment variables.

    0 讨论(0)
提交回复
热议问题