jhefreyzz

jhefreyzz

Failed to connect to websocket on production

I was able to deploy my first simple app to gigalixir and I it went all good until the socket connection was called in my frontend.

I have configured the UserSocket to add my frontend domain to check_origin option.

  socket "/socket", PickrWeb.UserSocket,
    websocket: true,
    longpoll: false,
    check_origin: ["https://pickr.vercel.app"]

I also updated the Endpoint url in prod.exs

config :pickr, PickrWeb.Endpoint,
  url: [host: "https://open-peaceful-springtail.gigalixirapp.com", port: 80]

I think I did the necessary steps to be able to connect but my frontend connection keeps logging 403 error

Here’s my gigalixir log

2020-11-09T12:22:07.506878+00:00 open-peaceful-springtail[open-peaceful-springtail-6d57796d8b-hxjln]: web.1  | 12:22:07.506 [error] Could not check origin for Phoenix.Socket transport.
2020-11-09T12:22:07.507036+00:00 open-peaceful-springtail[open-peaceful-springtail-6d57796d8b-hxjln]: web.1  | 
2020-11-09T12:22:07.507083+00:00 open-peaceful-springtail[open-peaceful-springtail-6d57796d8b-hxjln]: web.1  | Origin of the request: https://pickr.vercel.app
2020-11-09T12:22:07.507129+00:00 open-peaceful-springtail[open-peaceful-springtail-6d57796d8b-hxjln]: web.1  | 
2020-11-09T12:22:07.507173+00:00 open-peaceful-springtail[open-peaceful-springtail-6d57796d8b-hxjln]: web.1  | This happens when you are attempting a socket connection to
2020-11-09T12:22:07.507236+00:00 open-peaceful-springtail[open-peaceful-springtail-6d57796d8b-hxjln]: web.1  | a different host than the one configured in your config/
2020-11-09T12:22:07.507260+00:00 open-peaceful-springtail[open-peaceful-springtail-6d57796d8b-hxjln]: web.1  | files. For example, in development the host is configured
2020-11-09T12:22:07.507386+00:00 open-peaceful-springtail[open-peaceful-springtail-6d57796d8b-hxjln]: web.1  | to "localhost" but you may be trying to access it from
2020-11-09T12:22:07.507427+00:00 open-peaceful-springtail[open-peaceful-springtail-6d57796d8b-hxjln]: web.1  | "127.0.0.1". To fix this issue, you may either:
2020-11-09T12:22:07.507475+00:00 open-peaceful-springtail[open-peaceful-springtail-6d57796d8b-hxjln]: web.1  | 
2020-11-09T12:22:07.507511+00:00 open-peaceful-springtail[open-peaceful-springtail-6d57796d8b-hxjln]: web.1  |   1. update [url: [host: ...]] to your actual host in the
2020-11-09T12:22:07.507554+00:00 open-peaceful-springtail[open-peaceful-springtail-6d57796d8b-hxjln]: web.1  |      config file for your current environment (recommended)
2020-11-09T12:22:07.507602+00:00 open-peaceful-springtail[open-peaceful-springtail-6d57796d8b-hxjln]: web.1  | 
2020-11-09T12:22:07.507653+00:00 open-peaceful-springtail[open-peaceful-springtail-6d57796d8b-hxjln]: web.1  |   2. pass the :check_origin option when configuring your
2020-11-09T12:22:07.507822+00:00 open-peaceful-springtail[open-peaceful-springtail-6d57796d8b-hxjln]: web.1  |      endpoint or when configuring the transport in your
2020-11-09T12:22:07.507855+00:00 open-peaceful-springtail[open-peaceful-springtail-6d57796d8b-hxjln]: web.1  |      UserSocket module, explicitly outlining which origins
2020-11-09T12:22:07.507900+00:00 open-peaceful-springtail[open-peaceful-springtail-6d57796d8b-hxjln]: web.1  |      are allowed:
2020-11-09T12:22:07.507971+00:00 open-peaceful-springtail[open-peaceful-springtail-6d57796d8b-hxjln]: web.1  | 
2020-11-09T12:22:07.508019+00:00 open-peaceful-springtail[open-peaceful-springtail-6d57796d8b-hxjln]: web.1  |         check_origin: ["https://example.com",
2020-11-09T12:22:07.508063+00:00 open-peaceful-springtail[open-peaceful-springtail-6d57796d8b-hxjln]: web.1  |                        "//another.com:888", "//other.com"]
2020-11-09T12:22:07.508105+00:00 open-peaceful-springtail[open-peaceful-springtail-6d57796d8b-hxjln]: web.1  | 
2020-11-09T12:22:07.508220+00:00 open-peaceful-springtail[open-peaceful-springtail-6d57796d8b-hxjln]: web.1  | 

I’m really excited for this one, hopefully someone can help me.
Thank you very much.

Marked As Solved

jhefreyzz

jhefreyzz

Thank you for the replies, I already solved the issue thru slack channel.

I configure the config as below.

config :pickr, PickrWeb.Endpoint,
  url: [host: "pickr.vercel.app", port: 443, scheme: "https"]

Also Liked

mody5

mody5

Are you sure check_origin is an option of socket?

from what I see in the doc: Phoenix.Endpoint — Phoenix v1.8.8

check_origin should be set for websocket or longpoll, something like this maybe:

socket "/socket", PickrWeb.UserSocket,
    websocket: [ check_origin: ["https://pickr.vercel.app"] ],
    longpoll: [ check_origin: ["https://pickr.vercel.app"] ]

At least this is what the doc seems to say! but I would like to know if there is another way, because… what will happen to these “true” and “false” that were set for websocket and longpoll?

Where Next?

Popular in Questions Top

nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
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
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
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
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
dotdotdotPaul
Okay, I’m having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I’m sure I’...
New

Other popular topics Top

hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31194 112
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43806 214
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52774 488
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

We're in Beta

About us Mission Statement