跨域请求,映射代理
2020-07-15 本文已影响0人
罗不错
var express = require('express');
const {createProxyMiddleware } = require('http-proxy-middleware');
var app = express();
const port = require('../styleguide/port')
app.use('/api',createProxyMiddleware({
// 代理跨域目标接口
target: 'http://192.168.197.24:7001/', // 代码商店的后台服务
changeOrigin: true,
pathRewrite: {}
})
).use('/',createProxyMiddleware({
// 映射到自身页面
target: http://localhost:${port}/
,
changeOrigin: true,
pathRewrite: {}
})
).listen(port);
console.log(Proxy server is listen at port ${port}
);