Node.js 如何在React Native with Nodejs中设置代理目标?
尝试在react native with node中配置代理以运行axios调用 在server/package.json中尝试了以下代码Node.js 如何在React Native with Nodejs中设置代理目标?,node.js,react-native,express,axios,backend,Node.js,React Native,Express,Axios,Backend,尝试在react native with node中配置代理以运行axios调用 在server/package.json中尝试了以下代码 "proxy": { "/*": { "target": "http://localhost:5000/" } }, "scripts": { "start": "node index.js", "server": "nodemon index.js", "client": "cd ../clien
"proxy": {
"/*": {
"target": "http://localhost:5000/"
}
},
"scripts": {
"start": "node index.js",
"server": "nodemon index.js",
"client": "cd ../client && yarn ios",
"dev": "concurrently \"yarn server\" \"yarn client\""
}
服务器/authRouter.js
const authRouter = require('express').Router();
authRouter.get('/test', (req, res) => {
res.send('proxy success');
});
module.exports = authRouter;
server/index.js
const express = require('express');
const authRouter = require('./authRouter');
const app = express();
app.use('/auth', authRouter);
const PORT = process.env.PORT || 5000;
app.listen(PORT);
client/app.js
await axios.get('/auth/test');
当我运行Thread dev
并测试axios调用时,它会记录以下错误
LOG [Error: Network Error]
任何帮助都将不胜感激。尝试在axios中直接调用代理 我不知道为什么它不能那样工作,即使我过去有过一个问题