Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facilitate websocket traversal #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions lib/mu_identifier.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,33 @@ defmodule MuIdentifier do
port = 80
IO.puts("Running Proxy with Cowboy on port #{port}")

# TODO, this could be cleaner with `:cowboy.start_clear`
children = [
{Secret,%{}},
{Plug.Cowboy, scheme: :http, plug: Proxy, options: [port: port, compress: true]}
{Secret, %{}},
{Plug.Cowboy,
scheme: :http, plug: Proxy, options: [dispatch: dispatch, port: port, compress: true]}
]

Logger.info("Mu Identifier starting on port #{port}")

Supervisor.start_link(children, strategy: :one_for_one)
end

defp dispatch do
default = %{
host: "dispatcher",
port: 80,
path: "/"
}

f = fn req -> default |> Map.put(:path, req.path <> "?" <> req.qs) end

[
{:_,
[
{"/.mu/ws/[...]", WsHandler, {f, default}},
{:_, Plug.Cowboy.Handler, {Proxy, []}}
]}
]
end
end
3 changes: 3 additions & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ defmodule Proxy.Mixfile do
# Type `mix help deps` for more examples and options
defp deps do
[{:plug_mint_proxy, git: "https://github.com/madnificent/plug-mint-proxy.git", tag: "v0.2.0"},
{:cowboy_ws_proxy, git: "https://github.com/ajuvercr/elixir-cowboy-ws-proxy-handler.git", tag: "v0.1"},
{:uuid, "~> 1.1"},
{:gun, "~> 2.0.0-rc.2"},
{:replug, "~> 0.1.0"},
{:secure_random, "~> 0.5"},
{:exsync, "~> 0.2", only: :dev},
{:observer_cli, "~> 1.5"}]
end
end