高德地图内网部署,通过拦截请求实现
一、安装npm库
npm地址:ajax-hook - npm (npmjs.com)
-
NPM引入
npm install ajax-hook
二、实现代码,放到mainjs里面
import { proxy } from "ajax-hook";
proxy({
//请求发起前进入
onRequest: (config, handler) => {
// console.log(config.url)
if (config.url.toString().search('https://vdata.amap.com') != -1) {
config.url = 'http://171.11.12.121:60000/web2' + config.url.split('vdata.amap.com/')[1];
console.log(config.url)
} else if (config.url.toString().search('http://restapi.amap.com') != -1) {
config.url = 'http://171.11.12.121:60000/web3' + config.url.split('restapi.amap.com/')[1];
console.log(config.url)
} else if (config.url.toString().search('http://vector.amap.com') != -1) {
config.url = 'http://171.11.12.121:60000/web4' + config.url.split('vector.amap.com/')[1];
console.log(config.url)
} else if (config.url.toString().search('http://lbs.amap.com') != -1) {
config.url = 'http://171.11.12.121:60000/web5' + config.url.split('lbs.amap.com/')[1];
console.log(config.url)
}
handler.next(config);
},
onError: (err, handler) => {
console.log(err.type)
handler.next(err)
},
onResponse: (response, handler) => {
// console.log(response.response)
handler.next(response)
}
})
努力

浙公网安备 33010602011771号