feat: resolve relative URL manually

This commit is contained in:
Myriad-Dreamin 2024-12-12 23:43:10 +08:00 committed by Parsifa1
parent 3eee31a959
commit 50228956f6
No known key found for this signature in database
GPG key ID: 99B21766F86301CA
2 changed files with 9 additions and 13 deletions

13
Cargo.lock generated
View file

@ -4021,7 +4021,7 @@ dependencies = [
"serde_yaml",
"strum",
"sync-lsp",
"tinymist-assets 0.12.10 (registry+https://github.com/rust-lang/crates.io-index)",
"tinymist-assets",
"tinymist-query",
"tinymist-render",
"tinymist-world",
@ -4067,12 +4067,6 @@ dependencies = [
name = "tinymist-assets"
version = "0.12.10"
[[package]]
name = "tinymist-assets"
version = "0.12.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0d4ca0df1e38258ae8e1e0841173a903e7d6707c22632cb75c8661b0f1c4ed7"
[[package]]
name = "tinymist-derive"
version = "0.12.10"
@ -4163,8 +4157,7 @@ dependencies = [
"reqwest",
"serde",
"serde_json",
"tar",
"tinymist-assets 0.12.10 (registry+https://github.com/rust-lang/crates.io-index)",
"tinymist-assets",
"typst",
"typst-assets",
]
@ -4607,7 +4600,7 @@ dependencies = [
"reflexo-vec2svg",
"serde",
"serde_json",
"tinymist-assets 0.12.10 (registry+https://github.com/rust-lang/crates.io-index)",
"tinymist-assets",
"tokio",
"typst",
"typst-assets",

View file

@ -37,13 +37,16 @@ function retrieveWsArgs() {
/// The string `ws://127.0.0.1:23625` is a placeholder
/// Also, it is the default url to connect to.
let url = "ws://127.0.0.1:23625";
let urlObject = new URL("ws://127.0.0.1:23625", window.location.href);
/// Rewrite the protocol to websocket.
urlObject.protocol = urlObject.protocol.replace(/^https$/, 'wss').replace(/^http$/, 'ws');
if (location.href.startsWith("https://")) {
url = url.replace("ws://", "wss://")
urlObject.protocol = urlObject.protocol.replace(/^ws$/, 'wss');
}
/// Return a `WsArgs` object.
return { url, previewMode, isContentPreview: false };
return { url: urlObject.href, previewMode, isContentPreview: false };
}
/// `buildWs` returns a object, which keeps track of websocket