create-react-app设置代理
emer 发布于 2019-4-25 10:36 2625 次阅读
在src目录新建setupProxy.js文件
v1:
const proxy = require('http-proxy-middleware'); module.exports = function(app) { app.use(proxy('/api', { target: 'http://localhost:4000/',changeOrigin:true, pathRewrite:{ "^/api":"/" } })); };
v2:
// const proxy = require("http-proxy-middleware");const { createProxyMiddleware } = require("http-proxy-middleware");module.exports = function (app) {app.use("/api",createProxyMiddleware({target: "http://127.0.0.1:9000",changeOrigin: true,}));};