aswinmohanme

aswinmohanme

How to deploy Cross Origin LiveView?

TLDR;
How do I deploy a LiveView app such that I want the WebSocket to be hosted on a separate domain than the deployed app? I want my app liveview.com app to access the websockets on wss://notliveview.com/live.

I have changed my app.js to point to the full website, but the LiveView crashes and infinitely refreshes. I have changed the check_origin: policy to false and set session_options as, but still it does not connect. I can see on the network inspector that the cookie is not set when accessing wss://notliveview.com from a website hosted on liveview.com.

  @session_options [
    store: :cookie,
    key: "_app_web_key",
    signing_salt: "ARodNYY",
    same_site: "None",
    secure: true
  ]

Why ?

I have a monolithic Phoenix LiveView that currently serves the landing, privacy policy and terms-of-service from a single server. I also want to create a new blog, and I want to split it from the monolithic app and deploy it as a static site.

I have deployed my Phoenix LiveView app on Fly and the new marketing site (generated using a static site generator on Vercel). I’m planning to use Vercel as the front-facing website. When a person visits your site, it first checks if it matches the Vercel ones and if it doesn’t the rest of the request is reverse proxied through next.config.js: rewrites | Next.js through to the LiveView app.

It works fine for apps over HTTP, but does not work with Websockets because of the above issue, any pointers would be really helpful.

Marked As Solved

derek-zhou

derek-zhou

Entirely different domains will not share cookies, ever. You have 2 choices:

  • set the cookie on a apex domain and check the cookie in a sub-domain
  • forget about cookies and sessions all together

Also Liked

aswinmohanme

aswinmohanme

Here is the blog post about it in case it helps someone Superfast Webapps using NextJS, Vercel, LiveView and Fly.io · aswinmohan.me

Where Next?

Popular in Questions Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New

Other popular topics Top

AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement