i我试图上传我的项目(只有服务器端)客户端正在运行本地项目已上传到heroku网站,但我得到错误,我无法修复他们我使用React,节点js,表达,mongo DB
const express = require("express");
const app = express();
const express = require("express");
const cors = require("cors");
const setServerConfiguration = (app) => {
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(cors());
};
const mongoose = require("mongoose");
const UserRoute = require("./routes/User.route");
mongoose.connect("mongodb://localhost:27017/bank");
const setServerConfiguration = require("./config");
setServerConfiguration(app);
const port = process.env.PORT || 5000
app.use("/bank", (req,res)=>{
res.header("Access-Control-Allow-Origin", "https://nodejs-bank.herokuapp.com/bank");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
},UserRoute);
app.listen(port);
const baseUrl = "https://nodejs-bank.herokuapp.com/bank";
const [users, setUsers] = useState([]);
const { t } = useTranslation();
const fetchUsers = () => {
axios.get(baseUrl).then((response) => {
setUsers(response.data);
});
};
useEffect(() => {
fetchUsers();
}, []);
1条答案
按热度按时间lrpiutwd1#
嘿,在你的express应用程序中得到一个名为cors的包,并把它放在你的应用程序的顶部