1.node 启了一个服务器 地址是:http://localhost:9001
2.webpack 配置如下
proxyTable: {
'/api': {
target: 'http://localhost:9001',
changeOrigin: true,
secure: false
}
}
3.页面发送请求
const xml = new XMLHttpRequest()
xml.open('get', '/api')
xml.send()
4.服务端收到的路径是
/api
5.添加pathRewrite 修正
proxyTable: {
'/api': {
target: 'http://localhost:9001',
changeOrigin: true,
secure: false,
pathRewrite: {
'^/api': ''
}
}
}
6.这样服务端收到路径就是
/
7.实现代理