如何使用express来处理Heroku Create React App的路由?

时间:2018-04-07 10:48:05

标签: node.js reactjs express heroku create-react-app

我有一个create-react-app项目,该项目代理端口5000处的节点快速服务器。

当我们在本地部署它时,所有请求都会从客户端路由到后端服务器,并且中间页面会正确呈现。

但是,当我将它部署到Heroku时,流总是必须从/ route开始,因为任何其他URL直接命中快速服务器而不是从前端路由。

例如:https://consumesafe-dev.herokuapp.com有效

但是https://consumesafe-dev.herokuapp.com/dashboard直接转到节点服务器而不是从前端代理。

这是服务器的package.json:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
>

<!-- Your first child-->
<LinearLayout
    android:id="@+id/linlayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    >

    <include layout="@layout/toolbar"/>

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#4f83cc"
        style="@style/MyCustomTabLayout"
        app:tabMode="scrollable"
        >
    </android.support.design.widget.TabLayout>



    <android.support.v4.view.ViewPager

        android:id="@+id/viewPager"
        android:layout_below="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />


</LinearLayout>

<!--Your Fragment Container (Second Child) is now above the views above it-->

<FrameLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

</FrameLayout>

</FrameLayout>

和来自客户端的package.json:

{
  "name": "example-create-react-app-express",
  "version": "1.0.0",
  "scripts": {
    "client": "cd client && yarn start",
    "server": "nodemon server.js",
    "test": "cd client && npm install && yarn test",
    "dev": "concurrently --kill-others-on-fail \"yarn server\" \"yarn client\""
  },
  "dependencies": {
    "@google-cloud/language": "^1.0.0",
    "@google-cloud/vision": "^0.12.0",
    "async": "^2.6.0",
    "body-parser": "~1.4.2",
    "express": "^4.16.2",
    "google-cloud": "^0.57.0",
    "https": "^1.0.0",
    "method-override": "~2.0.2",
    "nodemon": "^1.17.3",
    "pg": "^7.4.1",
    "request": "^2.83.0",
    "sequelize": "^4.37.2",
    "winston": "^2.4.1"
  },
  "devDependencies": {
    "concurrently": "^3.5.1"
  }
}

0 个答案:

没有答案