Heroku:如何在客户端和服务器运行在不同端口上的情况下部署节点应用程序? [英] Heroku: How to deploy a node app with client and server running on different ports?

查看:43
本文介绍了Heroku:如何在客户端和服务器运行在不同端口上的情况下部署节点应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个git项目中有一个nodejs API作为服务器,而React/Redux应用程序作为客户端位于一个git项目中: https://github.com/lafisrap/fcc_nightlife.git

I have a nodejs API as server and React/Redux app as client located in one git project: https://github.com/lafisrap/fcc_nightlife.git

我想使用heroku cli在Heroku上部署它.

I want to deploy it on Heroku using the heroku cli.

package.json中的脚本部分为:

The scripts section in package.json is:

  "scripts": {
    "start-dev": "concurrently \"yarn run server\" \"yarn run client\"",
    "start": "yarn run server | yarn run client",
    "server": "babel-node server.js",
    "client": "node start-client.js",
    "lint": "eslint ."
  },

start-client.js:

start-client.js:

const args = [ 'start' ];
const opts = { stdio: 'inherit', cwd: 'client', shell: true };
require('child_process').spawn('yarn', args, opts);

在客户端文件夹中,我还有另一个package.json,它定义了客户端.它的脚本部分:

In the client folder I have another package.json which defines the client. The scripts section of it:

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

我做到了:

heroku create
git push heroku master

heroku create
git push heroku master

api运行正常.但是我不知道如何启动/访问客户端.

The api is running fine. But I don't know how to start/access the client.

推荐答案

不能在一个Heroku应用程序中部署两个服务.简而言之,您必须将它们部署为单独的Heroku测功机,才能部署两个应用程序.

You CAN NOT deploy two services in one Heroku app. In short, you have to deploy them to separate Heroku dynos to deploy two apps.

有关类似问题的此stackoverflow答案中提供了更多信息.

More information is provided in this stackoverflow answer to a similar question.

PS:构建React文件后,始终可以从API服务器提供JS文件.

PS: It is always an option to serve JS files from your API server after building React files.

希望这会有所帮助!

这篇关于Heroku:如何在客户端和服务器运行在不同端口上的情况下部署节点应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆