错误是您在数据库服务器的构建文件夹中使用端口 4000。在在线网站上它不识别它,并且端口 3306
所以,你的没问题server.js
,但App.js
你必须全部替换:
"http://localhost:3306/"
只需:
"/"
所以它将是:
...
fetch("/calculations")
...
fetch(`/calculations/add?calc=${calculationArray[calculationArray.length - 1]}`)
...
fetch(`/clear/`)
...
通过这种方式,您将在 react js 应用程序的同一端口上运行数据库服务器。
然后您必须运行npm run build
以创建build
文件夹,该文件夹将部署到 heroku。
或者
简单地说,在build
文件夹中你可以替换所有:
"http://localhost:4000/"
和:
"/"
别的东西:你不必上传node_modules
文件夹github
来部署你的应用程序。Heroku
不需要它。
您使用 git,因此您应该重命名.gitignore.txt
为 only.gitignore
没有任何格式扩展名,并编写:
node_modules
在其中,忽略此文件夹git push