Skip to content
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

WebIO + Interact + Mux does not work on pages other than "/" #382

Closed
cstjean opened this issue Jan 17, 2020 · 1 comment · Fixed by #396
Closed

WebIO + Interact + Mux does not work on pages other than "/" #382

cstjean opened this issue Jan 17, 2020 · 1 comment · Fixed by #396

Comments

@cstjean
Copy link
Contributor

cstjean commented Jan 17, 2020

On the current #master, with Interact v0.10.3 and Mux v0.7.1, Interact widgets with Mux only work on /:

julia> using WebIO, Interact, Mux
   
julia> function gui()
           but = button("click me")
           on(but) do _
               println("was clicked")
           end
           but
       end
gui (generic function with 1 method)

julia> Mux.@app app = (Mux.defaults,
                       page("/", req->gui()),
                       page("/hallo", req->gui()),
                       Mux.notfound())

julia> webio_serve(app, 8000)
Task (runnable) @0x00007f359a5adae0

Then the button at http://localhost:8000 works, but not the one at http://localhost:8000/hallo

I believe that @stefan911 found the solution in #241 (comment) but I can't quite figure it out from his comment.

@etpinard
Copy link
Contributor

Judging by

function webio_serve(app::Mux.App, args...)
websock = Mux.App(Mux.mux(
Mux.wdefaults,
Mux.route("/webio-socket", create_socket),
Mux.wclose,
Mux.notfound(),
))
Mux.serve(app, websock, args...)
end

the problem might be in

export const getMuxWSUrl = (): string => {
const {protocol, host, pathname} = window.location;
const wsProtocol = protocol == "https:" ? "wss:" : "ws:";
const basePath = pathname[pathname.length - 1] == "/" ? pathname : pathname + "/";
const wsPath = basePath + "webio-socket";
return `${wsProtocol}//${host}${wsPath}`;
};

which for http://localhost:8000/hallo returns ws://localhost:8000/hallo/webio-socket, but we need ws://localhost:8000/webio-socket/hallo for Mux.route("/webio-socket", create_socket) to pick up the request.


Before I make a PR, any info on the best way to test patches in the JS code would be much appreciated. Thanks!

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

Successfully merging a pull request may close this issue.

2 participants