【发布时间】:2021-06-11 03:12:05
【问题描述】:
在本地机器上一切正常,如果我的服务器设置正确,请告诉我
项目结构
/client/--React frontend app
/client/package.json
/index.js
/package.json -- express server
在我的 /index.js 中
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const path = require("path");
const app = express();
app.use(cors());
app.use(express.json());
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
}
app.listen(process.env.B_PORT || 5000, () => {
console.log(`Express server Up and Running - Port : ${process.env.B_PORT}`);
});
在我的 /client/package.json 中
{
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"proxy": "http://localhost:5000",
}
我收到 405 不允许发布请求,但是当我执行 http://myec2ip:5000 时,我可以从 express 获得 json 响应。
我缺少什么配置?
【问题讨论】:
标签: node.js reactjs express nginx amazon-ec2