fix(dx): merge script and fix host rewrite

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei 2024-11-18 22:05:45 +08:00
parent a60db7eda6
commit 3fa3bd5fc5
No known key found for this signature in database
GPG Key ID: 0F62D33977F021F7
2 changed files with 31 additions and 35 deletions

View File

@ -1,39 +1,6 @@
<!doctype html>
<html>
<head>
<script type="module">
const searchParams = new URLSearchParams(window.location.search)
const debugHost = searchParams.get("debug-host")
const resetSessionStorage = () => {
sessionStorage.removeItem("debug-host")
}
const resetParams = searchParams.delete("debug-host")
if (resetParams) {
resetSessionStorage()
}
const debugHostInSessionStorage = sessionStorage.getItem("debug-host")
const host = debugHost || debugHostInSessionStorage || "https://localhost:2233"
if (debugHost) {
sessionStorage.setItem("debug-host", debugHost)
}
const createRefreshRuntimeScript = `
import RefreshRuntime from "${host}/@react-refresh";
RefreshRuntime.injectIntoGlobalHook(window);
window.$RefreshReg$ = () => {};
window.$RefreshSig$ = () => (type) => type;
window.__vite_plugin_react_preamble_installed__ = true;
`
const $script = document.createElement("script")
$script.innerHTML = createRefreshRuntimeScript
$script.type = "module"
document.head.appendChild($script)
</script>
<title>Debug Proxy</title>
<script type="module" src="./__debug_proxy.ts"></script>
</head>

View File

@ -1,7 +1,36 @@
const host = "https://localhost:2233"
globalThis["__DEBUG_PROXY__"] = true
const searchParams = new URLSearchParams(window.location.search)
const debugHost = searchParams.get("debug-host")
const resetSessionStorage = () => {
sessionStorage.removeItem("debug-host")
}
const resetParams = searchParams.get("reset")
if (resetParams) {
resetSessionStorage()
}
const debugHostInSessionStorage = sessionStorage.getItem("debug-host")
const host = debugHost || debugHostInSessionStorage || "https://localhost:2233"
if (debugHost) {
sessionStorage.setItem("debug-host", debugHost)
}
const createRefreshRuntimeScript = `
import RefreshRuntime from "${host}/@react-refresh";
RefreshRuntime.injectIntoGlobalHook(window);
window.$RefreshReg$ = () => {};
window.$RefreshSig$ = () => (type) => type;
window.__vite_plugin_react_preamble_installed__ = true;
`
const $script = document.createElement("script")
$script.innerHTML = createRefreshRuntimeScript
$script.type = "module"
document.head.append($script)
fetch(`${host}`)
.then((res) => res.text())
.then((html) => {