Update routers to hide and show api's docs

pull/2376/head
saneery 5 years ago
parent b717c37c0b
commit 9a76297651
  1. 21
      apps/block_scout_web/lib/block_scout_web/api_router.ex
  2. 46
      apps/block_scout_web/lib/block_scout_web/router.ex
  3. 2
      apps/block_scout_web/lib/block_scout_web/templates/address_contract_verification/new.html.eex
  4. 6
      apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex
  5. 5
      apps/block_scout_web/lib/block_scout_web/views/address_contract_verification_view.ex
  6. 3
      apps/block_scout_web/lib/block_scout_web/web_router.ex
  7. 6
      apps/block_scout_web/test/block_scout_web/controllers/api/v1/health_controller_test.exs
  8. 2
      apps/block_scout_web/test/block_scout_web/controllers/api_docs_controller_test.exs

@ -5,7 +5,6 @@ defmodule BlockScoutWeb.ApiRouter do
use BlockScoutWeb, :router
alias BlockScoutWeb.API.RPC
alias BlockScoutWeb.Plug.GraphQL
pipeline :api do
plug(:accepts, ["json"])
@ -19,8 +18,6 @@ defmodule BlockScoutWeb.ApiRouter do
scope "/", BlockScoutWeb.API.V1 do
get("/supply", SupplyController, :supply)
get("/health", HealthController, :health)
post("/decompiled_smart_contract", DecompiledSmartContractController, :create)
post("/verified_smart_contracts", VerifiedSmartContractController, :create)
@ -38,24 +35,6 @@ defmodule BlockScoutWeb.ApiRouter do
end
end
# Needs to be 200 to support the schema introspection for graphiql
@max_complexity 200
forward("/graphql", Absinthe.Plug,
schema: BlockScoutWeb.Schema,
analyze_complexity: true,
max_complexity: @max_complexity
)
forward("/graphiql", Absinthe.Plug.GraphiQL,
schema: BlockScoutWeb.Schema,
interface: :advanced,
default_query: GraphQL.default_query(),
socket: BlockScoutWeb.UserSocket,
analyze_complexity: true,
max_complexity: @max_complexity
)
# For backward compatibility. Should be removed
scope "/", BlockScoutWeb.API.RPC do
pipe_through(:api)

@ -2,6 +2,10 @@ defmodule BlockScoutWeb.Router do
use BlockScoutWeb, :router
alias BlockScoutWeb.Plug.GraphQL
alias BlockScoutWeb.{ApiRouter, WebRouter}
forward("/wobserver", Wobserver.Web.Router)
forward("/admin", BlockScoutWeb.AdminRouter)
pipeline :browser do
plug(:accepts, ["html"])
@ -11,13 +15,24 @@ defmodule BlockScoutWeb.Router do
plug(BlockScoutWeb.CSPHeader)
end
forward("/wobserver", Wobserver.Web.Router)
forward("/admin", BlockScoutWeb.AdminRouter)
pipeline :api do
plug(:accepts, ["json"])
end
scope "/", BlockScoutWeb.API.V1, as: :api_v1 do
pipe_through(:api)
get("/api/v1/health", HealthController, :health)
end
if Application.get_env(:block_scout_web, BlockScoutWeb.ApiRouter)[:enabled] do
forward("/api", BlockScoutWeb.ApiRouter)
scope "/verify_smart_contract" do
pipe_through(:api)
post("/contract_verifications", BlockScoutWeb.AddressContractVerificationController, :create)
end
if Application.get_env(:block_scout_web, ApiRouter)[:enabled] do
forward("/api", ApiRouter)
# For backward compatibility. Should be removed
# Needs to be 200 to support the schema introspection for graphiql
@max_complexity 200
@ -35,9 +50,28 @@ defmodule BlockScoutWeb.Router do
analyze_complexity: true,
max_complexity: @max_complexity
)
else
scope "/", BlockScoutWeb do
pipe_through(:browser)
get("/api_docs", PageNotFoundController, :index)
get("/eth_rpc_api_docs", PageNotFoundController, :index)
end
end
scope "/", BlockScoutWeb do
pipe_through(:browser)
get("/api_docs", APIDocsController, :index)
get("/eth_rpc_api_docs", APIDocsController, :eth_rpc)
end
if Application.get_env(:block_scout_web, BlockScoutWeb.WebRouter)[:enabled] do
if Application.get_env(:block_scout_web, WebRouter)[:enabled] do
forward("/", BlockScoutWeb.WebRouter)
else
scope "/", BlockScoutWeb do
pipe_through(:browser)
forward("/", APIDocsController, :index)
end
end
end

@ -9,7 +9,7 @@
<h1 class="smart-contract-title"><%= gettext "New Smart Contract Verification" %></h1>
<%= form_for @changeset,
api_v1_address_contract_verification_path(@conn, :create),
address_contract_verification_path(@conn, :create),
[],
fn f -> %>

@ -8,6 +8,7 @@
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav">
<%= if Application.get_env(:block_scout_web, BlockScoutWeb.WebRouter)[:enabled] do %>
<li class="nav-item dropdown">
<a class="nav-link topnav-nav-link dropdown-toggle" href="#" id="navbarBlocksDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="nav-link-icon">
@ -56,6 +57,8 @@
<%= gettext("Accounts") %>
<% end %>
</li>
<% end %>
<%= if Application.get_env(:block_scout_web, BlockScoutWeb.ApiRouter)[:enabled] do %>
<li class="nav-item dropdown">
<a href="#" role="button" id="navbarAPIsDropdown" class="nav-link topnav-nav-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="nav-link-icon">
@ -81,6 +84,7 @@
) %>
</div>
</li>
<% end %>
<li class="nav-item dropdown nav-item-networks">
<a class="nav-link topnav-nav-link dropdown-toggle active-icon js-show-network-selector <%= if dropdown_nets() == [], do: "disabled" %>" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="nav-link-icon">
@ -91,6 +95,7 @@
</li>
</ul>
<!-- Search navbar -->
<%= if Application.get_env(:block_scout_web, BlockScoutWeb.WebRouter)[:enabled] do %>
<div class="search-form d-lg-flex d-inline-block">
<%= form_for @conn, chain_path(@conn, :search), [class: "form-inline my-2 my-lg-0", method: :get, enforce_utf8: false], fn f -> %>
<div class="input-group" title='<%= gettext("Search by address, token symbol name, transaction hash, or block number") %>'>
@ -119,6 +124,7 @@
<button class="btn btn-outline-success my-2 my-sm-0 sr-only hidden" type="submit"><%= gettext "Search" %></button>
<% end %>
</div>
<% end %>
</div>
</div>
</nav>

@ -1,8 +1,3 @@
defmodule BlockScoutWeb.AddressContractVerificationView do
use BlockScoutWeb, :view
alias BlockScoutWeb.ApiRouter.Helpers
def api_v1_address_contract_verification_path(conn, action) do
"/api" <> Helpers.api_v1_address_contract_verification_path(conn, action)
end
end

@ -199,9 +199,6 @@ defmodule BlockScoutWeb.WebRouter do
get("/chain_blocks", ChainController, :chain_blocks, as: :chain_blocks)
get("/api_docs", APIDocsController, :index)
get("/eth_rpc_api_docs", APIDocsController, :eth_rpc)
get("/:page", PageNotFoundController, :index)
end
end

@ -1,8 +1,6 @@
defmodule BlockScoutWeb.API.V1.HealthControllerTest do
use BlockScoutWeb.ConnCase
alias BlockScoutWeb.ApiRouter.Helpers
describe "GET last_block_status/0" do
test "returns error when there are no blocks in db", %{conn: conn} do
request = get(conn, api_v1_health_path(conn, :health))
@ -49,8 +47,4 @@ defmodule BlockScoutWeb.API.V1.HealthControllerTest do
} = Poison.decode!(request.resp_body)
end
end
def api_v1_health_path(conn, action) do
"/api" <> Helpers.api_v1_health_path(conn, action)
end
end

@ -1,7 +1,7 @@
defmodule BlockScoutWeb.APIDocsControllerTest do
use BlockScoutWeb.ConnCase
import BlockScoutWeb.WebRouter.Helpers, only: [api_docs_path: 2]
import BlockScoutWeb.Router.Helpers, only: [api_docs_path: 2]
describe "GET index/2" do
test "renders documentation tiles for each API module#action", %{conn: conn} do

Loading…
Cancel
Save