Phoenix Liveview in Proxy - Longpoll

We have been using Phoenix live view in one of our projects. It is deployed under Proxy.

I find that WebSockets won’t work under a proxy. So alternate solution is using long poll.

I want to know two things.

  1. we are using Phoenix 1.5


import {Socket} from "phoenix"
import NProgress from "nprogress"
import {LiveSocket} from "phoenix_live_view"

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


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

I have changed the connection from WebSocket to the long poll. But things are not working after I made these two changes.

I made only the two changes which are mentioned above. What I have done wrong or what I am missing to make it work in long poll.

  1. Performance-wise does the Phoenix live view will it go down since because I have used Longpoll instead of WebSocket? Is there any alternative available?

Any insight on these two questions will be a great help for me. Your help is greatly appreciated. Thanks.

1 Like

You are passing the transport as query string param – you need:

let liveSocket = new LiveSocket("/live", Socket, {
  params: {_csrf_token: csrfToken},
  transport: LongPoll

I tried this. But still the websocket shows the status as pending. Liveview not working

Is there any chance that Phoenix Live View Websockets can be used under Proxy? Thanks