Skip to content

Instantly share code, notes, and snippets.

@oivoodoo
Created June 7, 2021 10:28
Show Gist options
  • Save oivoodoo/99869858731117d18916b25fbc66245a to your computer and use it in GitHub Desktop.
Save oivoodoo/99869858731117d18916b25fbc66245a to your computer and use it in GitHub Desktop.
proxy_example.ex
defmodule EyelevelEx.Proxy.Application do
@moduledoc false
use Application
def start(_type, _args) do
import Supervisor.Spec, warn: false
opts = [strategy: :one_for_one, name: EyelevelEx.Proxy.Supervisor]
Supervisor.start_link(children(Mix.env()), opts)
end
def children(:test), do: []
def children(_) do
[
{
Plug.Cowboy,
scheme: :http,
plug: EyelevelEx.Proxy.Plug,
port: port(),
dispatch: [{:_, [phoenix_live_reload(), websocket(), master_proxy()]}]
}
]
end
def port do
(System.get_env("PORT") || "4000") |> String.to_integer()
end
def phoenix_live_reload do
{
"/phoenix/live_reload/socket/websocket",
Phoenix.Endpoint.Cowboy2Handler,
{
Phoenix.Endpoint.Cowboy2Adapter,
{EyelevelExWeb.Endpoint, Phoenix.LiveReloader.Socket, :websocket}
}
}
end
def websocket do
{
"/cable/websocket",
Phoenix.Endpoint.Cowboy2Handler,
{
Phoenix.Endpoint.Cowboy2Adapter,
{EyelevelExWeb.Endpoint, EyelevelExWeb.UserSocket, :websocket}
}
}
end
def master_proxy do
{:_, Plug.Cowboy.Handler, {EyelevelEx.Proxy.Plug, []}}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment