react跨域跳转不好用,把src换台机器就好用

通过前端localhost:3000/api 直接访问后端时,页面并没有跳转。单独访问后端127.0.0.1:7001/api是可以的。

img

package.json中的"http-proxy-middleware": "^2.0.6",

setupProxy.js中的代码


const { createProxyMiddleware } = require('http-proxy-middleware')

module.exports = function(app) {
  console.log("hello");      **//中间的hello并没有输出**
  app.use(
    '/api',
    createProxyMiddleware({
      target: 'http://localhost:7001/',
      changeOrigin: true,
    })
  )
}

DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option. Starting the development server... 这个是说:api 弃用了
弃用警告:“onBeforeSetupMiddleware”选项已弃用。请使用“setupMiddlewares”选项。正在启动开发服务器。。。