简体   繁体   English

如何在 heroku 上使用服务器部署 React 应用程序?

[英]How to Deploy React app with server on heroku?

I am deploying a React app to Heroku.我正在将 React 应用程序部署到 Heroku。 On my local machine, I have my react folder and I have a server folder so that I can make API calls to log people in. Normally I run npm start in my react folder and then open a separate terminal to and run node server.js .在我的本地机器上,我有我的 react 文件夹和一个 server 文件夹,这样我就可以调用 API 来让人们登录。通常我在我的 react 文件夹中运行npm start然后打开一个单独的终端并运行node server.js . This way I can use my app and log in.这样我就可以使用我的应用程序并登录。

The problem is that when I deploy to heroku I only see my app.问题是当我部署到 heroku 时,我只看到我的应用程序。 How do I get heroku to run my server.js file as well?如何让 heroku 也运行我的 server.js 文件? I have done it before but that was a year ago.我以前做过,但那是一年前的事了。

Here is the git repo for my app: https://github.com/budstamper/WebChop The server.js is in the parent folder and the app is in the 'client' folder.这是我的应用程序的 git 存储库: https://github.com/budstamper/WebChop server.js 在父文件夹中,应用程序在“客户端”文件夹中。

Your repo link takes to me to a 404 error so could not see your file.您的 repo 链接将我带到 404 错误,因此无法看到您的文件。 I use a devDependency called concurrently to run my app folder and server.js on one terminal.我使用concurrently调用的 devDependency 在一个终端上运行我的应用程序文件夹和server.js Here is how i deploy to heroku with the concurrently dependency.这是我如何部署到 heroku 并concurrently依赖。

`    "scripts": {
"client": "cd client && npm run start",
"server": "nodemon server.js",
"build": "cd client && npm run build",
"dev": "concurrently --kill-others-on-fail \"npm run server\" \"npm run client\"",
"start": "node server.js",
"heroku-postbuild": "cd client && npm install && npm install --only=dev --no-shrinkwrap && npm run build"

` `

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM