Skip to content
Draft
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
1 change: 1 addition & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ config :exqlite, force_build: true
config :ethui, Ethui.Stacks,
graph_node_image: "graphprotocol/graph-node:f02dfa2",
ipfs_image: "ipfs/kubo:v0.34.1",
explorer_image: "ghcr.io/ethui/explorer:latest",
pg_image: "postgres:17.4",
anvil_bin: System.get_env("ANVIL_BIN", "anvil"),
docker_host: System.get_env("DOCKER_HOST", "172.17.0.1"),
Expand Down
21 changes: 21 additions & 0 deletions lib/ethui/services/explorer.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
defmodule Ethui.Services.Explorer do
@moduledoc """
GenServer that manages a global `@ethui/explorer` instace, to be shared by all anvil instances
This wraps a MuontipTrap Daemon
"""

use Ethui.Services.Docker,
image: &__MODULE__.docker_image/0,
named_args: [
network: "ethui-stacks",
name: "ethui-stacks-explorer"
]

def docker_image do
config()[:explorer_image]
end

defp config do
Application.get_env(:ethui, Ethui.Stacks)
end
end
3 changes: 3 additions & 0 deletions lib/ethui/stacks/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ defmodule Ethui.Stacks.Supervisor do
# global Postgres service
{Ethui.Services.Pg, []},

# owned instance of ethui-explorer
{Ethui.Services.Explorer, []},

# services supervisor
MultiStackSupervisor,
Server
Expand Down
27 changes: 25 additions & 2 deletions lib/ethui_web/controllers/proxy_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ defmodule EthuiWeb.ProxyController do

def reverse_proxy(conn, _params), do: conn |> send_resp(404, "Not found")

defp proxy_component(conn, params, {slug, nil}), do: anvil(conn, params, slug)
defp proxy_component(%{method: "POST"} = conn, params, {slug, nil}),
do: anvil(conn, params, slug)

defp proxy_component(%{method: "GET"} = conn, params, {slug, nil}),
do: explorer_redirect(conn, params, slug)

defp proxy_component(conn, params, {slug, "graph"}),
do: subgraph_generic(conn, params, slug, 8000)
Expand All @@ -29,6 +33,9 @@ defmodule EthuiWeb.ProxyController do
defp proxy_component(conn, params, {_slug, "ipfs"}),
do: ipfs(conn, params)

defp proxy_component(conn, params, {_slug, "explorer"}),
do: explorer(conn, params)

defp proxy_component(%Plug.Conn{assigns: assigns} = conn, _params, _proxy) do
Logger.error("cannot proxy #{inspect(assigns)}")

Expand All @@ -49,6 +56,22 @@ defmodule EthuiWeb.ProxyController do
end
end

defp explorer_redirect(conn, _params, _slug) do
conn |> redirect(external: "http://google.com")
end

defp explorer(conn, %{"proxied_path" => proxied_path}) do
case Ethui.Services.Explorer.ip() do
{:ok, ip} ->
forward(conn, "http://#{ip}:3000/#{Enum.join(proxied_path, "/")}")

_ ->
conn
|> put_status(:not_found)
|> json(%{error: "Explorer not running"})
end
end

defp subgraph_generic(conn, %{"proxied_path" => proxied_path}, slug, target_port) do
case Graph.ip_from_slug(slug) do
{:ok, ip} ->
Expand All @@ -70,7 +93,7 @@ defmodule EthuiWeb.ProxyController do
_ ->
conn
|> put_status(:not_found)
|> json(%{error: "Stack not found"})
|> json(%{error: "IPFS not found"})
end
end

Expand Down