为什么我不能在ReactJS中将本地主机更改为自定义域名?

huangapple go评论63阅读模式
英文:

Why couldn't I can change my localhost to custom domain name in ReactJS?

问题

我想在我的React应用中将localhost更改为自定义域名。我已经在我的host文件中使用自定义域名进行了编辑,并且在我的package.json中设置了homepage:"http://domainname.com"。但在运行npm run build和npm start之后,它仍然在localhost上运行,项目在运行,但没有使用我的自定义域名。

英文:

I want to change localhost to custom domain name in my react app.I have edited my hostfile with custom domain name and my package.json as homepage:"http://domainname.com"/. But after npm run build and npm start, it still runs on localhost, the project runs but without my custom domain name.

答案1

得分: 2

将你的React应用托管在像NetlifyGithub Pages这样的托管提供商上,并在那里更改你的域名。
React开发服务器只会在本地主机上运行。

英文:

Host your react app in a hosting provider like Netlify or Github pages and change your domain there.
React development server will only run on localhost

答案2

得分: 1

你不能在公共域上运行开发服务器。有许多方法可以构建和部署您的应用程序到生产环境。这将使其从任何地方可访问。问题在于您的计算机无法在域上托管服务器,而不是在本地主机上。您可以使用不同的托管提供商,如Netlify、Heroku、Firebase Hosting或GitHub Pages。

英文:

You cannot run a development server in a public domain. There are many ways you could build and deploy your app to production. This will make it available from anywhere. The thing is that your computer can't host the server on the domain rather than localhost. You can use different hosting providers like Netlify, Heroku, Firebase Hosting or GitHub Pages.

huangapple
  • 本文由 发表于 2023年3月3日 21:52:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/75627942.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定