如何在共享托管服务器上设置react / redux / express应用程序?

时间:2018-07-27 02:16:41

标签: node.js reactjs express

因此,我使用带有Node.js和Express的create-react-app构建了我的第一个React应用程序。在本地,我为我的API运行端口5000(即“ api / searches”(仅一个端点)),并在端口3000上同时使用主要的React应用程序。

我正在尝试使其在共享主机上运行。我通过SSH进入服务器,安装了节点和NPM。我运行“ npm run build”脚本来创建dist文件夹,并将其上载到服务器上的目录。网站上的HTML可以渲染,但是我的API无效,并且可能存在其他问题,因此目前没有任何功能。如何完成此设置?我真的不知道有什么问题吗?

我也正在使用redux,对它并不太了解,因此不确定是否也是一个问题。在我看来,我的应用程序基本上是一种使用mLab连接到我的mongoDB的表单。实际上,这里对这个GitHub项目进行了一些修改:

https://github.com/bradtraversy/mern_shopping_list

在浏览器控制台中,我看到:

Failed to load resource: the server responded with a status of 404 () - /api/searches:1 

这是我的主要package.json文件

{
  "name": "name goes here",
  "version": "1.0.0",
  "main": "server.js",
  "scripts": {
    "client-install": "npm install --prefix client",
    "start": "node server.js",
    "server": "nodemon server.js",
    "client": "npm start --prefix client",
    "dev": "concurrently \"npm run server\" \"npm run client\"",
    "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
  },
  "author": "",
  "license": "MIT",
  "dependencies": {
    "body-parser": "^1.18.3",
    "concurrently": "^3.6.0",
    "express": "^4.16.3",
    "mongoose": "^5.1.6",
    "nightmare": "^3.0.1",
    "nodemailer": "^4.6.7",
    "uuid": "^3.3.2"
  },
  "devDependencies": {
    "nodemon": "^1.17.5"
  }
}

这是我的客户端文件夹中的package.json文件:

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "axios": "^0.18.0",
    "bootstrap": "^4.1.1",
    "react": "^16.4.1",
    "react-dom": "^16.4.1",
    "react-redux": "^5.0.7",
    "react-scripts": "1.1.4",
    "react-transition-group": "^2.3.1",
    "reactstrap": "^6.1.0",
    "redux": "^4.0.0",
    "redux-thunk": "^2.3.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "proxy": "http://localhost:5000",
  "homepage": "https://www.example.com/myapp/" <- this is how I got it working on my server I think?
}

0 个答案:

没有答案