在express配置中已经使用了中间件http-proxy-middleware并且配置了转发app.use('/api',proxy({target:'http://x.x.x.x.',changeOrigin:true,pathRewrite:{'^/api':'/'}}));而在app.get方法中使用axios的时候会报错:app.get('/index/test',function(req,res){axios.get('/api/index/getdata.html?page=1')//这里如果写成http://x.x.x.x/index/getdata.html?page=1就不会报错.then(result=>{console.log(result);returnres.send('test');})});output(node:12952)UnhandledPromiseRejectionWarning:Unhandledpromiserejection(rejectionid:2):Error:Requestfailedwithstatuscode404(node:12952)[DEP0018]DeprecationWarning:Unhandledpromiserejectionsaredeprecated.Inthefuture,promiserejectionsthatarenothandledwillterminatetheNode.jsprocesswithanon-zeroexitcode.其中我想要使用/api,不知道怎么实现?
精慕HU
相关分类