[GH-ISSUE #63] Unable to proxy websockets? #56

Open
opened 2026-03-02 23:02:03 +03:00 by kerem · 3 comments
Owner

Originally created by @teamon on GitHub (May 11, 2022).
Original GitHub issue: https://github.com/agrinman/tunnelto/issues/63

I'm trying to use Phoenix LiveView over tunnelto. Everything works just fine without proxy or when using ngrok.
With tunnelto I get:

[info] Sent 200 in 2ms
[info] CONNECTED TO Phoenix.LiveView.Socket in 25µs
  Transport: :websocket
  Serializer: Phoenix.Socket.V2.JSONSerializer
  Parameters: %{...}
[debug] LiveView session was misconfigured or the user token is outdated.

1) Ensure your session configuration in your endpoint is in a module attribute:

    @session_options [
      ...
    ]

2) Change the `plug Plug.Session` to use said attribute:

    plug Plug.Session, @session_options

3) Also pass the `@session_options` to your LiveView socket:

    socket "/live", Phoenix.LiveView.Socket,
      websocket: [connect_info: [session: @session_options]]

4) Ensure the `protect_from_forgery` plug is in your router pipeline:

    plug :protect_from_forgery

5) Define the CSRF meta tag inside the `<head>` tag in your layout: 

    <%= csrf_meta_tag() %>

6) Pass it forward in your app.js:

    let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content");
    let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}});

This happens in all browsers.
Standard HTTP requests are proxies just fine.
tunnelto version is 0.1.18.

Originally created by @teamon on GitHub (May 11, 2022). Original GitHub issue: https://github.com/agrinman/tunnelto/issues/63 I'm trying to use Phoenix LiveView over tunnelto. Everything works just fine without proxy or when using ngrok. With tunnelto I get: ``` [info] Sent 200 in 2ms [info] CONNECTED TO Phoenix.LiveView.Socket in 25µs Transport: :websocket Serializer: Phoenix.Socket.V2.JSONSerializer Parameters: %{...} [debug] LiveView session was misconfigured or the user token is outdated. 1) Ensure your session configuration in your endpoint is in a module attribute: @session_options [ ... ] 2) Change the `plug Plug.Session` to use said attribute: plug Plug.Session, @session_options 3) Also pass the `@session_options` to your LiveView socket: socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]] 4) Ensure the `protect_from_forgery` plug is in your router pipeline: plug :protect_from_forgery 5) Define the CSRF meta tag inside the `<head>` tag in your layout: <%= csrf_meta_tag() %> 6) Pass it forward in your app.js: let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content"); let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}}); ``` This happens in all browsers. Standard HTTP requests are proxies just fine. tunnelto version is 0.1.18.
Author
Owner

@renataogarcia commented on GitHub (May 13, 2022):

I'm trying to use websocksets with Vite and the problem I have is that when running:

tunnelto -p 3000 -s mydomain

It binds https://mydomain.tunnelto.dev to http://localhost:3000 as expected but the wss://mydomain.tunnelto.dev doesn't work and the browser fails with:
WebSocket connection to 'wss://mydomain.tunnelto.dev/' failed

No errors on tunnelto output.

I've also tried 1.19 version mentioned here without success.

It works with ngrok and localtunnel.

<!-- gh-comment-id:1125702713 --> @renataogarcia commented on GitHub (May 13, 2022): I'm trying to use websocksets with Vite and the problem I have is that when running: ``` tunnelto -p 3000 -s mydomain ``` It binds `https://mydomain.tunnelto.dev` to `http://localhost:3000` as expected but the `wss://mydomain.tunnelto.dev` doesn't work and the browser fails with: `WebSocket connection to 'wss://mydomain.tunnelto.dev/' failed` No errors on tunnelto output. I've also tried 1.19 version mentioned [here](https://github.com/agrinman/tunnelto/issues/51#issuecomment-882199533) without success. It works with ngrok and localtunnel.
Author
Owner

@mitkodkn commented on GitHub (May 12, 2023):

Any updates on this?

<!-- gh-comment-id:1546106458 --> @mitkodkn commented on GitHub (May 12, 2023): Any updates on this?
Author
Owner

@Kynth commented on GitHub (Feb 5, 2025):

Still not working in 1.20

<!-- gh-comment-id:2637245639 --> @Kynth commented on GitHub (Feb 5, 2025): Still not working in 1.20
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tunnelto#56
No description provided.