@quicktvui/web-cli 2.3.0 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -302,11 +302,16 @@
|
|
|
302
302
|
|
|
303
303
|
/**
|
|
304
304
|
* 判断 URL 是否为跨域请求(需要代理)
|
|
305
|
+
* 排除 data:, blob:, javascript:, about: 等非 HTTP 协议 URL
|
|
305
306
|
*/
|
|
306
307
|
function isCrossOrigin(url) {
|
|
307
|
-
if (!url) return false;
|
|
308
|
+
if (!url || typeof url !== 'string') return false;
|
|
309
|
+
// 非网络协议的 URL 不需要代理
|
|
310
|
+
if (/^(data|blob|javascript|about):/i.test(url)) return false;
|
|
308
311
|
try {
|
|
309
312
|
var urlObj = new URL(url, window.location.href);
|
|
313
|
+
// 非 http/https 协议也不代理
|
|
314
|
+
if (urlObj.protocol !== 'http:' && urlObj.protocol !== 'https:') return false;
|
|
310
315
|
return urlObj.origin !== LOCAL_ORIGIN;
|
|
311
316
|
} catch (e) {
|
|
312
317
|
return false;
|
|
@@ -320,6 +325,8 @@
|
|
|
320
325
|
function toProxyUrl(url) {
|
|
321
326
|
try {
|
|
322
327
|
var urlObj = new URL(url, window.location.href);
|
|
328
|
+
// 只代理 http/https 协议
|
|
329
|
+
if (urlObj.protocol !== 'http:' && urlObj.protocol !== 'https:') return url;
|
|
323
330
|
var proxyPath = '/proxy/' + urlObj.protocol.replace(':', '') + '/' + urlObj.host + urlObj.pathname + urlObj.search + urlObj.hash;
|
|
324
331
|
return proxyPath;
|
|
325
332
|
} catch (e) {
|
|
@@ -327,11 +334,32 @@
|
|
|
327
334
|
}
|
|
328
335
|
}
|
|
329
336
|
|
|
337
|
+
// ===== 38989 debug server URL 转换 =====
|
|
338
|
+
// es3-vue 在非生产环境下会将 assets/xxx 转换为 http://127.0.0.1:38989/assets/xxx
|
|
339
|
+
// 但在 web 环境下这些资源就在 dist/dev/assets/ 中,应转为相对路径
|
|
340
|
+
var DEBUG_SERVER_RE = /https?:\/\/[^/:]+:38989\//;
|
|
341
|
+
function convertDebugServerUrl(url) {
|
|
342
|
+
if (typeof url === 'string' && DEBUG_SERVER_RE.test(url)) {
|
|
343
|
+
var converted = url.replace(DEBUG_SERVER_RE, './');
|
|
344
|
+
console.log('[DevProxy] 38989 URL converted:', url, '->', converted);
|
|
345
|
+
return converted;
|
|
346
|
+
}
|
|
347
|
+
return null;
|
|
348
|
+
}
|
|
349
|
+
|
|
330
350
|
// ===== 拦截 fetch =====
|
|
331
351
|
var originalFetch = window.fetch;
|
|
332
352
|
window.fetch = function(input, init) {
|
|
333
353
|
var url = (typeof input === 'string') ? input : (input && input.url ? input.url : input);
|
|
334
|
-
|
|
354
|
+
// 优先处理 38989 debug server URL → 相对路径
|
|
355
|
+
var debugConverted = convertDebugServerUrl(url);
|
|
356
|
+
if (debugConverted) {
|
|
357
|
+
if (typeof input === 'string') {
|
|
358
|
+
input = debugConverted;
|
|
359
|
+
} else if (input instanceof Request) {
|
|
360
|
+
input = new Request(debugConverted, init || {});
|
|
361
|
+
}
|
|
362
|
+
} else if (isCrossOrigin(url)) {
|
|
335
363
|
var proxyUrl = toProxyUrl(url);
|
|
336
364
|
console.log('[DevProxy] fetch:', url, '->', proxyUrl);
|
|
337
365
|
if (typeof input === 'string') {
|
|
@@ -346,7 +374,11 @@
|
|
|
346
374
|
// ===== 拦截 XMLHttpRequest =====
|
|
347
375
|
var originalXHROpen = XMLHttpRequest.prototype.open;
|
|
348
376
|
XMLHttpRequest.prototype.open = function(method, url, async, user, password) {
|
|
349
|
-
|
|
377
|
+
// 优先处理 38989 debug server URL → 相对路径
|
|
378
|
+
var debugConverted = convertDebugServerUrl(url);
|
|
379
|
+
if (debugConverted) {
|
|
380
|
+
url = debugConverted;
|
|
381
|
+
} else if (isCrossOrigin(url)) {
|
|
350
382
|
var proxyUrl = toProxyUrl(url);
|
|
351
383
|
console.log('[DevProxy] XHR:', url, '->', proxyUrl);
|
|
352
384
|
url = proxyUrl;
|
|
@@ -360,6 +392,11 @@
|
|
|
360
392
|
Object.defineProperty(HTMLImageElement.prototype, 'src', {
|
|
361
393
|
...originalImageSrcDescriptor,
|
|
362
394
|
set(value) {
|
|
395
|
+
// 优先处理 38989 debug server URL → 相对路径
|
|
396
|
+
var debugConverted = convertDebugServerUrl(value);
|
|
397
|
+
if (debugConverted) {
|
|
398
|
+
return originalImageSrcDescriptor.set.call(this, debugConverted);
|
|
399
|
+
}
|
|
363
400
|
if (isCrossOrigin(value)) {
|
|
364
401
|
var proxyUrl = toProxyUrl(value);
|
|
365
402
|
console.log('[DevProxy] Image:', value, '->', proxyUrl);
|