flat: 暂存
This commit is contained in:
@@ -1,47 +1,56 @@
|
||||
// amap_proxy.ts
|
||||
const hookScript = (): void => {
|
||||
// 1. 内网入口地址
|
||||
const proxyBase = 'http://10.213.6.207:19010';
|
||||
|
||||
// 2. 域名映射表 (Key: 原始域名, Value: 内网代理路径)
|
||||
// 注意:顺序很重要,长路径优先匹配(虽然后缀不同一般没事)
|
||||
const domainMap: Record<string, string> = {
|
||||
'https://webapi.amap.com/maps': '/maps', // 特殊处理 maps
|
||||
'https://webapi.amap.com': '/webAmap',
|
||||
'https://restapi.amap.com': '/restAmap',
|
||||
'https://a.amap.com': '/amap',
|
||||
'https://lbs.amap.com': '/lbs',
|
||||
'http://vector.amap.com': '/vector', // http 协议
|
||||
// --- 核心 API ---
|
||||
'https://webapi.amap.com/maps': '/maps', // JS API 入口
|
||||
'https://webapi.amap.com': '/webAmap', // 静态资源/插件
|
||||
'https://c-webapi.amap.com': '/cwebAmap', // [新增] 辅助配置接口
|
||||
'https://restapi.amap.com': '/restAmap', // 服务接口(搜索/地理编码等)
|
||||
'https://a.amap.com': '/amap', // 辅助资源
|
||||
'https://lbs.amap.com': '/lbs', // LBS 服务
|
||||
|
||||
// --- 矢量瓦片 ---
|
||||
'https://vdata.amap.com': '/vdata',
|
||||
// 批量处理 vdata01-04
|
||||
'https://vdata01.amap.com': '/vdata01',
|
||||
'https://vdata02.amap.com': '/vdata02',
|
||||
'https://vdata03.amap.com': '/vdata03',
|
||||
'https://vdata04.amap.com': '/vdata04',
|
||||
// 批量处理 webst01-04
|
||||
|
||||
// --- 卫星图瓦片 ---
|
||||
'https://webst01.is.autonavi.com': '/webst01',
|
||||
'https://webst02.is.autonavi.com': '/webst02',
|
||||
'https://webst03.is.autonavi.com': '/webst03',
|
||||
'https://webst04.is.autonavi.com': '/webst04',
|
||||
// 批量处理 wprd01-04
|
||||
|
||||
// --- 栅格图瓦片 ---
|
||||
'https://wprd01.is.autonavi.com': '/wprd01',
|
||||
'https://wprd02.is.autonavi.com': '/wprd02',
|
||||
'https://wprd03.is.autonavi.com': '/wprd03',
|
||||
'https://wprd04.is.autonavi.com': '/wprd04',
|
||||
|
||||
// --- 矢量数据 (HTTP 协议) ---
|
||||
'http://vector.amap.com': '/vector',
|
||||
};
|
||||
|
||||
// 通用替换函数
|
||||
/**
|
||||
* URL 替换核心逻辑
|
||||
*/
|
||||
const replaceUrl = (url: string): string => {
|
||||
// 如果已经是代理地址,不再处理
|
||||
if (url.indexOf(proxyBase) !== -1) {
|
||||
return url;
|
||||
}
|
||||
|
||||
for (const [origin, path] of Object.entries(domainMap)) {
|
||||
if (url.indexOf(origin) !== -1) {
|
||||
// 将 https://vdata01.amap.com/xxx 替换为 http://10.213.6.207:19010/vdata01/xxx
|
||||
// 将原始域名替换为: http://10.213.6.207:19010/xxx
|
||||
return url.replace(origin, `${proxyBase}${path}`);
|
||||
}
|
||||
}
|
||||
return url;
|
||||
};
|
||||
|
||||
// --- 拦截 Script 标签 (JS API 加载) ---
|
||||
const scriptDescriptor = Object.getOwnPropertyDescriptor(HTMLScriptElement.prototype, 'src');
|
||||
if (scriptDescriptor && scriptDescriptor.set) {
|
||||
const nativeSet = scriptDescriptor.set;
|
||||
@@ -55,7 +64,7 @@ const hookScript = (): void => {
|
||||
});
|
||||
}
|
||||
|
||||
// --- 拦截 XMLHttpRequest (瓦片、搜索、矢量数据) ---
|
||||
|
||||
const nativeOpen = XMLHttpRequest.prototype.open;
|
||||
XMLHttpRequest.prototype.open = function (
|
||||
method: string,
|
||||
@@ -69,7 +78,7 @@ const hookScript = (): void => {
|
||||
return nativeOpen.call(this, method, newUrl, async, user, password);
|
||||
};
|
||||
|
||||
console.log('高德地图内网全量代理已激活');
|
||||
console.log('[AMap Proxy] 高德地图内网代理拦截已激活 (包含 c-webapi 支持)');
|
||||
};
|
||||
|
||||
hookScript();
|
||||
Reference in New Issue
Block a user