设置Heroku +创建React应用+ React Router +外部api

时间:2018-07-22 21:37:33

标签: node.js heroku react-router create-react-app

我正在尝试在同一服务器上设置 create-react-app和节点。理想情况下,我希望将其设置为

'/ app / **'-->返回react build包

(注意:这将包括create-react-app + react-router v4)

'/ api / **'→全部在节点服务器中处理

我遵循了本教程: https://medium.freecodecamp.org/how-to-make-create-react-app-work-with-a-node-backend-api-7c5c48acb1b0

据我所知,在其中设置了以下内容:

在服务器中

  1. Api路由配置为端口5000
  2. 但仅为所有路由提供client / build / index.html

    Create-react-app:

  3. 通过端口3000提供服务

  4. package.json设置为使'localhost:5000'为代理(因此api 请求被重定向到该端口,而不是3000。

但是问题是无法从外部访问api(即在heroku appname.heorkuapp.com/api/hello上不返回json输出)。

我已经看了很多遍,但在这方面没有找到太多帮助。任何帮助深表感谢!

0 个答案:

没有答案