react 中配置 http-proxy-middleware

在src目录中创建 setupProxy.js文件
添加如下配置

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

module.exports = function (app) {
    app.use(
        createProxyMiddleware('/api', {
            target: 'http://localhost:5000',
            changeOrigin: true,
            pathRewrite: {
                '^/api': ''
            }
        })
    )
}
posted @ 2021-07-30 15:22  _Otis  阅读(197)  评论(0编辑  收藏  举报