-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
executable file
·44 lines (44 loc) · 1.69 KB
/
index.html
File metadata and controls
executable file
·44 lines (44 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!doctype html>
<html lang="">
<head>
<!--
关键:必须在 Vite 注入 @vite/client 之前劫持 WebSocket
这个脚本必须是 <head> 中的第一个元素!
-->
<script>
;(function () {
if (typeof window !== 'undefined') {
var currentHost = window.location.hostname
var OriginalWebSocket = window.WebSocket
window.WebSocket = function (url, protocols) {
var fixedUrl = url
if (typeof url === 'string') {
if (url.indexOf('localhost') !== -1 || url.indexOf('0.0.0.0') !== -1) {
fixedUrl = url.replace(/localhost|0\.0\.0\.0/g, currentHost)
console.log('🔧 [HMR修复] WebSocket URL:', url, '->', fixedUrl)
}
}
if (protocols !== undefined) {
return new OriginalWebSocket(fixedUrl, protocols)
}
return new OriginalWebSocket(fixedUrl)
}
window.WebSocket.prototype = OriginalWebSocket.prototype
window.WebSocket.CONNECTING = OriginalWebSocket.CONNECTING
window.WebSocket.OPEN = OriginalWebSocket.OPEN
window.WebSocket.CLOSING = OriginalWebSocket.CLOSING
window.WebSocket.CLOSED = OriginalWebSocket.CLOSED
console.log('✅ [HMR修复] WebSocket劫持已安装,当前主机:', currentHost)
}
})()
</script>
<meta charset="UTF-8" />
<link rel="icon" href="/单LOGO.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Universal Fullstack Framework</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>