# LiveView and Multiple Endpoints

**URL:** <https://community.fly.io/t/liveview-and-multiple-endpoints/6103>\
**Category:** Phoenix\
**Tags:** live\_view\
**Created:** [July 21, 2022, 12:24pm UTC](https://community.fly.io/t/liveview-and-multiple-endpoints/6103 "2022-07-21T12:24:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbcaprell](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/jbcaprell/32/1269_2.png) [@jbcaprell](https://community.fly.io/u/jbcaprell)\
**Post date:** [July 21, 2022, 12:24pm UTC](https://community.fly.io/t/liveview-and-multiple-endpoints/6103/1 "2022-07-21T12:24:30Z")

</div>

Hello!

I came across the following thread while working to accomplish something similar:

> [@Umbrella Elixir app with multiple endpoints](https://community.fly.io/t/umbrella-elixir-app-with-multiple-endpoints/2649/3):
>
> If you are planning on running the child applications all in the same VM, you could also create a new child application that starts a bare-bones endpoint which does the routing to the appropriate endpoint. The big caveat with this approach is the endpoint socket declarations are intercepted in a special case which won’t work if forwarding from another plug upstream, so to support this approach you’d need to specify the socket declarations of all the other children in the child proxy app. If that…

I’m hoping to deploy an application that will serve up different endpoints for different hosts; eg, a request to `foo.com` will be routed to FooWeb.Endpoint, and a request to `bar.com` to BarWeb.Endpoint.

The routing part is easy. It does, though, break LiveView somehow—I get a 404 on the socket. Chris mentions something about “need[ing] to specify the `socket` declarations” on the child proxy application, but I’m not sure exactly what that means. I’m wondering if he, or someone else, could expound upon that!

Thanks!

---

<div class="post-metadata">

**Author:** ![chrismccord](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/chrismccord/32/50976_2.png) [@chrismccord](https://community.fly.io/u/chrismccord)\
**Post date:** [July 21, 2022, 1:29pm UTC](https://community.fly.io/t/liveview-and-multiple-endpoints/6103/2 "2022-07-21T13:29:16Z")

</div>

Your proxy endpoint will need to have a socket declaration with matching session information each of Plug.Session of the proxied endpoints:

```nohighlight
  @proxy_endpoints [foo: FooWeb.Endpiont, bar: BarWeb.Endpiont]
  for {app, endpoint} <- @proxy_endpoints do
    @app app
    @session Application.compile_env!(app, endpoint)[:session]
    socket "/#{@app}/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session]]
  end
  ...
end

```

And your child endpoints can reference their session lookup from the same application config:

```auto
defmodule FooWeb.Endpoint do
  @session_options Application.compile_env!(:foo, FooWeb.Endpoint)[:session]
  plug Plug.Session, @session_options
end

```

Make sense?

---

<div class="post-metadata">

**Author:** ![jbcaprell](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/jbcaprell/32/1269_2.png) [@jbcaprell](https://community.fly.io/u/jbcaprell)\
**Post date:** [July 21, 2022, 1:39pm UTC](https://community.fly.io/t/liveview-and-multiple-endpoints/6103/3 "2022-07-21T13:39:37Z")

</div>

That does! I think I was turned around on it because my initial proxy endpoint was only utilizing `plug_cowboy`, so I just wasn’t thinking about the `socket/3` macro.

This is great, Chris! Thanks so much!
