我正在构建 vue 应用程序,我的应用程序需要从客户端向服务器发出 api 请求,还需要代理任何请求。
这是我的vue.config.js
const producer = require('./src/kafka/producer');
const bodyParser = require('body-parser')
module.exports = {
devServer: {
setup: function (app, server) {
app.use(bodyParser.json())
app.post('/send-message', function (req, res) {
producer.send(req.body)
.then(() => {
res.json({result: true, error: null});
})
.catch((e) => {
res.status(500).json({result: false, error: e});
})
});
},
proxy: {
'/v2/order/by-number': {
target: 'http://address-here'
}
}
}
};
如您所见,我正在使用 body-parser app.use(bodyParser.json())
添加后,代理停止为我工作。显示错误后对/send-message 的请求冻结
代理错误:无法将请求路径-此处从 localhost:8080 代理到http://address-here
互联网搜索并没有找到解决方案。