Skip to content

Commit ad7b94d

Browse files
committed
move cowboy ws proxy to seperate git repo
1 parent 72c4243 commit ad7b94d

File tree

9 files changed

+23
-139
lines changed

9 files changed

+23
-139
lines changed

config/config.exs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ config :dispatcher,
4444
# log whenever a layer starts processing
4545
log_layer_start_processing: CH.system_boolean("LOG_LAYER_START_PROCESSING"),
4646
# log whenever a layer matched, and if no matching layer was found
47-
log_layer_matching: CH.system_boolean("LOG_LAYER_MATCHING"),
48-
log_ws_all: CH.system_boolean("LOG_WS_ALL"),
49-
log_ws_backend: CH.system_boolean("LOG_WS_BACKEND"),
50-
log_ws_frontend: CH.system_boolean("LOG_WS_FRONTEND"),
51-
log_ws_unhandled: CH.system_boolean("LOG_WS_UNHANDLED")
47+
log_layer_matching: CH.system_boolean("LOG_LAYER_MATCHING")
5248

5349
# It is also possible to import configuration files, relative to this
5450
# directory. For example, you can emulate configuration per environment

lib/dispatcher/log.ex

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ defmodule Dispatcher.Log do
22
@type log_name ::
33
:log_layer_start_processing
44
| :log_layer_matching
5-
| :log_ws_all
6-
| :log_ws_backend
7-
| :log_ws_frontend
8-
| :log_ws_unhandled
95

106
@spec log(log_name, any()) :: any()
117
def log(name, content) do

lib/manipulators/remove_accept_encoding_header.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ defmodule Manipulators.RemoveAcceptEncodingHeader do
33

44
@impl true
55
def headers(headers, connection) do
6-
# headers =
7-
# headers
8-
# |> Enum.reject( &match?( {"accept_encoding", _}, &1 ) )
6+
headers =
7+
headers
8+
|> Enum.reject( &match?( {"accept_encoding", _}, &1 ) )
99
{headers, connection}
1010
end
1111

lib/matcher.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ defmodule Matcher do
478478
defp sort_and_group_accept_headers(accept) do
479479
accept
480480
|> safe_parse_accept_header()
481-
|> IO.inspect(label: "parsed_accept_header")
481+
# |> IO.inspect(label: "parsed_accept_header")
482482
|> Enum.sort_by(&elem(&1, 3))
483483
|> Enum.group_by(&elem(&1, 3))
484484
|> Map.to_list()

lib/mu_dispatcher.ex

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ defmodule MuDispatcher do
1111

1212
children = [
1313
# this is kinda strange, but the 'plug:' field is not used when 'dispatch:' is provided (my understanding)
14-
{Plug.Adapters.Cowboy,
14+
{Plug.Cowboy,
1515
scheme: :http, plug: PlugRouterDispatcher, options: [dispatch: dispatch, port: port]}
1616
]
1717

@@ -21,10 +21,24 @@ defmodule MuDispatcher do
2121
end
2222

2323
defp dispatch do
24+
default = %{
25+
host: "localhost",
26+
port: 80,
27+
path: "/"
28+
}
29+
30+
f = fn req ->
31+
{_, target} =
32+
:cowboy_req.parse_qs(req)
33+
|> Enum.find(fn {head, _} -> head == "target" end)
34+
35+
Dispatcher.get_websocket(target)
36+
end
37+
2438
[
2539
{:_,
2640
[
27-
{"/ws/[...]", WebsocketHandler, %{}},
41+
{"/ws/[...]", WsHandler, {f, default}},
2842
{:_, Plug.Cowboy.Handler, {PlugRouterDispatcher, []}}
2943
]}
3044
]

lib/plug_router_dispatcher.ex

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
alias Dispatcher.Log
2-
31
defmodule PlugRouterDispatcher do
42
use Plug.Router
53

lib/websocket_handler.ex

Lines changed: 0 additions & 122 deletions
This file was deleted.

mix.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ defmodule Dispatcher.Mixfile do
2727
# Type `mix help deps` for more examples and options
2828
defp deps do
2929
[
30+
{:cowboy_ws_proxy, git: "https://github.com/ajuvercr/elixir-cowboy-ws-proxy-handler.git", tag: "v0.1"},
3031
{:plug_mint_proxy,
3132
git: "https://github.com/madnificent/plug-mint-proxy.git", tag: "v0.0.2"},
3233
# {:plug, "~> 1.10.4"},

mix.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"castore": {:hex, :castore, "0.1.11", "c0665858e0e1c3e8c27178e73dffea699a5b28eb72239a3b2642d208e8594914", [:mix], [], "hexpm", "91b009ba61973b532b84f7c09ce441cba7aa15cb8b006cf06c6f4bba18220081"},
44
"cowboy": {:hex, :cowboy, "2.9.0", "865dd8b6607e14cf03282e10e934023a1bd8be6f6bacf921a7e2a96d800cd452", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "2c729f934b4e1aa149aff882f57c6372c15399a20d54f65c8d67bef583021bde"},
55
"cowboy_telemetry": {:hex, :cowboy_telemetry, "0.3.1", "ebd1a1d7aff97f27c66654e78ece187abdc646992714164380d8a041eda16754", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3a6efd3366130eab84ca372cbd4a7d3c3a97bdfcfb4911233b035d117063f0af"},
6+
"cowboy_ws_proxy": {:git, "https://github.com/ajuvercr/elixir-cowboy-ws-proxy-handler.git", "e015e27775af30d4e3d7ca5629d97191cca61555", [tag: "v0.1"]},
67
"cowlib": {:hex, :cowlib, "2.11.0", "0b9ff9c346629256c42ebe1eeb769a83c6cb771a6ee5960bd110ab0b9b872063", [:make, :rebar3], [], "hexpm", "2b3e9da0b21c4565751a6d4901c20d1b4cc25cbb7fd50d91d2ab6dd287bc86a9"},
78
"exsync": {:hex, :exsync, "0.2.4", "5cdc824553e0f4c4bf60018a9a6bbd5d3b51f93ef8401a0d8545f93127281d03", [:mix], [{:file_system, "~> 0.2", [hex: :file_system, repo: "hexpm", optional: false]}], "hexpm", "f7622d8bb98abbe473aa066ae46f91afdf7a5346b8b89728404f7189d2e80896"},
89
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},

0 commit comments

Comments
 (0)