如何在反应中将 localhost:3000 更改为 custom.domain

Far*_*deh 5 javascript frontend cross-domain reactjs react-scripts

 "scripts": {
    "start": "cross-env NODE_PATH=src react-scripts start",
    "build": "cross-env NODE_PATH=src react-scripts build",
  }
Run Code Online (Sandbox Code Playgroud)

如何在反应中将 localhost:3000 更改为 custom.domain

daj*_*oto 8

如果您询问纯粹在本地为您的应用程序提供服务,您只需HOST在脚本之前附加一个值即可。就像其他人指出的那样,你可以用一个PORT值来做。

"scripts": {
  "start": "HOST=custom.domain react-scripts start"
}
Run Code Online (Sandbox Code Playgroud)

然后在您的计算机上,您只需确保已使用适当的指令配置主机文件

127.0.0.1 custom.domain
Run Code Online (Sandbox Code Playgroud)

假设您已运行启动脚本并正在为该站点提供服务,您现在可以通过 url 访问它http://custom.domain:3000


小智 -2

如果您想更改域名,您需要将您的 React 应用程序上传到网络空间。如果您想更改端口,您需要在启动脚本中发送参数。

"scripts": {
    "start": "set port=4213 && react-scripts start",
}
Run Code Online (Sandbox Code Playgroud)

在这种情况下,端口将为 4213。因此站点将在 http://localhost:4213 上运行