Skip to content

y-sweet server's auth_doc API return wrong url when server start with --url-prefix #398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kindy opened this issue Apr 22, 2025 · 0 comments

Comments

@kindy
Copy link

kindy commented Apr 22, 2025

auth_doc in crates/y-sweet/src/server.rs generate url & baseUrl,
when url_prefix has path, the return url is wrong (baseUrl is correct).

for example, when start y-sweet like this:

y-sweet serve --url-prefix=http://localhost/doc/ws/

auth_doc response will be like this:

  • url: ws://localhost/d/<doc_id>/ws
  • base_url: http://localhost/doc/ws/d/<doc_id>

maybe remove the prefix slash can fix it?
url = url.join(&format!("/d/{doc_id}/ws")).unwrap();

src of url & base_url
  let url = if let Some(url_prefix) = &server_state.url_prefix {
        let mut url = url_prefix.clone();
        let scheme = if url.scheme() == "https" { "wss" } else { "ws" };
        url.set_scheme(scheme).unwrap();
        url = url.join(&format!("/d/{doc_id}/ws")).unwrap();
        url.to_string()
    } else {
        format!("ws://{host}/d/{doc_id}/ws")
    };

    let base_url = if let Some(url_prefix) = &server_state.url_prefix {
        let mut url_prefix = url_prefix.to_string();
        if !url_prefix.ends_with('/') {
            url_prefix = format!("{url_prefix}/");
        }

        format!("{url_prefix}d/{doc_id}")
    } else {
        format!("http://{host}/d/{doc_id}")
    };

I meet this when I try the example deployment.
I make some hack like this:

--- a/deploy/Caddyfile
+++ b/deploy/Caddyfile
@@ -1,5 +1,5 @@
 http://localhost {
-    reverse_proxy /doc/ws/* y-sweet:8080
+    reverse_proxy /d/* y-sweet:8080
     reverse_proxy /* demos:3000
 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant