Skip to content

Commit

Permalink
Add remote url prefix mode node discovery in plug mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
IanLuites committed Feb 14, 2017
1 parent 21b7820 commit 5bdbce3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/wobserver/util/node/remote.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ defmodule Wobserver.Util.Node.Remote do
local?: false,
]

@remote_url_prefix Application.get_env(:wobserver, :remote_url_prefix, "")

@spec call(map, endpoint :: String.t) :: String.t | :error
defp call(%{host: host, port: port}, endpoint) do
request =
Expand All @@ -42,7 +44,7 @@ defmodule Wobserver.Util.Node.Remote do

def metrics(remote_node = %{local?: false}) do
remote_node
|> call("/metrics/n/local")
|> call("#{@remote_url_prefix}/metrics/n/local")
end

def metrics(%{local?: true}) do
Expand All @@ -53,15 +55,15 @@ defmodule Wobserver.Util.Node.Remote do
@spec api(remote_node :: map, path :: String.t) :: String.t | :error
def api(remote_node, path) do
remote_node
|> call("/api" <> path)
|> call("#{@remote_url_prefix}/api" <> path)
end

@spec socket_proxy(atom | map) :: {pid, String.t} | {:error, String.t}
def socket_proxy(%{local?: true}), do: socket_proxy(:local)

def socket_proxy(%{name: name, host: host, port: port}) do
connection =
%URI{scheme: "ws", host: host, port: port, path: "/ws"}
%URI{scheme: "ws", host: host, port: port, path: "#{@remote_url_prefix}/ws"}
|> URI.to_string
|> ClientProxy.connect

Expand Down

0 comments on commit 5bdbce3

Please sign in to comment.