Merge pull request #2989 from poanetwork/vb-fix-eth-rpc-api-path

Introduce API_PATH env var
pull/2995/head
Victor Baranov 5 years ago committed by GitHub
commit ba0e1119c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      CHANGELOG.md
  2. 9
      apps/block_scout_web/assets/js/lib/try_eth_api.js
  3. 3
      apps/block_scout_web/config/config.exs
  4. 3
      apps/block_scout_web/config/dev.exs
  5. 3
      apps/block_scout_web/config/prod.exs
  6. 21
      apps/block_scout_web/lib/block_scout_web/views/api_docs_view.ex
  7. 5
      apps/block_scout_web/lib/block_scout_web/views/tokens/instance/overview_view.ex
  8. 4
      apps/block_scout_web/priv/gettext/default.pot
  9. 4
      apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
  10. 6
      apps/block_scout_web/test/block_scout_web/views/api_docs_view_test.exs

@ -3,7 +3,7 @@
### Features ### Features
### Fixes ### Fixes
- [#2989](https://github.com/poanetwork/blockscout/pull/2989) - Introduce API_PATH env var
- [#2897](https://github.com/poanetwork/blockscout/pull/2897) - remove duplicate indexes - [#2897](https://github.com/poanetwork/blockscout/pull/2897) - remove duplicate indexes
### Chore ### Chore

@ -44,8 +44,9 @@ function parseInput (input) {
} }
} }
function dropDomain (url) { function composeRequestUrl () {
return new URL(url).pathname const url = $('[data-endpoint-url]').attr('data-endpoint-url')
return url
} }
$('button[data-try-eth-api-ui-button-type="execute"]').click(event => { $('button[data-try-eth-api-ui-button-type="execute"]').click(event => {
@ -64,10 +65,8 @@ $('button[data-try-eth-api-ui-button-type="execute"]').click(event => {
clickedButton.html(loadingText) clickedButton.html(loadingText)
} }
const url = $('[data-endpoint-url]').attr('data-endpoint-url')
$.ajax({ $.ajax({
url: dropDomain(url), url: composeRequestUrl(),
type: 'POST', type: 'POST',
data: JSON.stringify(formData), data: JSON.stringify(formData),
dataType: 'json', dataType: 'json',

@ -41,7 +41,8 @@ config :block_scout_web, BlockScoutWeb.Endpoint,
url: [ url: [
scheme: System.get_env("BLOCKSCOUT_PROTOCOL") || "http", scheme: System.get_env("BLOCKSCOUT_PROTOCOL") || "http",
host: System.get_env("BLOCKSCOUT_HOST") || "localhost", host: System.get_env("BLOCKSCOUT_HOST") || "localhost",
path: System.get_env("NETWORK_PATH") || "/" path: System.get_env("NETWORK_PATH") || "/",
api_path: System.get_env("API_PATH") || "/"
], ],
render_errors: [view: BlockScoutWeb.ErrorView, accepts: ~w(html json)], render_errors: [view: BlockScoutWeb.ErrorView, accepts: ~w(html json)],
pubsub: [name: BlockScoutWeb.PubSub] pubsub: [name: BlockScoutWeb.PubSub]

@ -21,7 +21,8 @@ config :block_scout_web, BlockScoutWeb.Endpoint,
url: [ url: [
scheme: "http", scheme: "http",
host: System.get_env("BLOCKSCOUT_HOST") || "localhost", host: System.get_env("BLOCKSCOUT_HOST") || "localhost",
path: System.get_env("NETWORK_PATH") || "/" path: System.get_env("NETWORK_PATH") || "/",
api_path: System.get_env("API_PATH") || "/"
], ],
https: [ https: [
port: (port && port + 1) || 4001, port: (port && port + 1) || 4001,

@ -23,7 +23,8 @@ config :block_scout_web, BlockScoutWeb.Endpoint,
scheme: System.get_env("BLOCKSCOUT_PROTOCOL") || "https", scheme: System.get_env("BLOCKSCOUT_PROTOCOL") || "https",
port: System.get_env("PORT"), port: System.get_env("PORT"),
host: System.get_env("BLOCKSCOUT_HOST") || "localhost", host: System.get_env("BLOCKSCOUT_HOST") || "localhost",
path: System.get_env("NETWORK_PATH") || "/" path: System.get_env("NETWORK_PATH") || "/",
api_path: System.get_env("API_PATH") || "/"
] ]
config :block_scout_web, BlockScoutWeb.Tracer, env: "production", disabled?: true config :block_scout_web, BlockScoutWeb.Tracer, env: "production", disabled?: true

@ -34,10 +34,17 @@ defmodule BlockScoutWeb.APIDocsView do
end) end)
end end
def blockscout_url do def blockscout_url(is_api) do
url_params = Application.get_env(:block_scout_web, BlockScoutWeb.Endpoint)[:url] url_params = Application.get_env(:block_scout_web, BlockScoutWeb.Endpoint)[:url]
host = url_params[:host] host = url_params[:host]
path = url_params[:path]
path =
if is_api do
url_params[:api_path]
else
url_params[:path]
end
scheme = Keyword.get(url_params, :scheme, "http") scheme = Keyword.get(url_params, :scheme, "http")
if host != "localhost" do if host != "localhost" do
@ -49,12 +56,18 @@ defmodule BlockScoutWeb.APIDocsView do
end end
def api_url do def api_url do
blockscout_url() is_api = true
is_api
|> blockscout_url()
|> Path.join("api") |> Path.join("api")
end end
def eth_rpc_api_url do def eth_rpc_api_url do
blockscout_url() is_api = true
is_api
|> blockscout_url()
|> Path.join("api/eth_rpc") |> Path.join("api/eth_rpc")
end end
end end

@ -4,7 +4,7 @@ defmodule BlockScoutWeb.Tokens.Instance.OverviewView do
alias BlockScoutWeb.CurrencyHelpers alias BlockScoutWeb.CurrencyHelpers
alias Explorer.Chain.{Address, SmartContract, Token} alias Explorer.Chain.{Address, SmartContract, Token}
import BlockScoutWeb.APIDocsView, only: [blockscout_url: 0] import BlockScoutWeb.APIDocsView, only: [blockscout_url: 1]
@tabs ["token_transfers", "metadata"] @tabs ["token_transfers", "metadata"]
@ -55,7 +55,8 @@ defmodule BlockScoutWeb.Tokens.Instance.OverviewView do
def qr_code(conn, token_id, hash) do def qr_code(conn, token_id, hash) do
token_instance_path = token_instance_path(conn, :show, to_string(hash), to_string(token_id)) token_instance_path = token_instance_path(conn, :show, to_string(hash), to_string(token_id))
url = Path.join(blockscout_url(), token_instance_path) is_api = false
url = Path.join(blockscout_url(is_api), token_instance_path)
url url
|> QRCode.to_png() |> QRCode.to_png()

@ -898,7 +898,7 @@ msgstr ""
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:4 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:4
#: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:7 #: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:7
#: lib/block_scout_web/views/address_view.ex:308 #: lib/block_scout_web/views/address_view.ex:308
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:71 #: lib/block_scout_web/views/tokens/instance/overview_view.ex:72
#: lib/block_scout_web/views/tokens/overview_view.ex:35 #: lib/block_scout_web/views/tokens/overview_view.ex:35
#: lib/block_scout_web/views/transaction_view.ex:314 #: lib/block_scout_web/views/transaction_view.ex:314
msgid "Token Transfers" msgid "Token Transfers"
@ -1774,7 +1774,7 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/tokens/instance/metadata/index.html.eex:18 #: lib/block_scout_web/templates/tokens/instance/metadata/index.html.eex:18
#: lib/block_scout_web/templates/tokens/instance/overview/_tabs.html.eex:10 #: lib/block_scout_web/templates/tokens/instance/overview/_tabs.html.eex:10
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:72 #: lib/block_scout_web/views/tokens/instance/overview_view.ex:73
msgid "Metadata" msgid "Metadata"
msgstr "" msgstr ""

@ -898,7 +898,7 @@ msgstr ""
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:4 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:4
#: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:7 #: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:7
#: lib/block_scout_web/views/address_view.ex:308 #: lib/block_scout_web/views/address_view.ex:308
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:71 #: lib/block_scout_web/views/tokens/instance/overview_view.ex:72
#: lib/block_scout_web/views/tokens/overview_view.ex:35 #: lib/block_scout_web/views/tokens/overview_view.ex:35
#: lib/block_scout_web/views/transaction_view.ex:314 #: lib/block_scout_web/views/transaction_view.ex:314
msgid "Token Transfers" msgid "Token Transfers"
@ -1774,7 +1774,7 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/tokens/instance/metadata/index.html.eex:18 #: lib/block_scout_web/templates/tokens/instance/metadata/index.html.eex:18
#: lib/block_scout_web/templates/tokens/instance/overview/_tabs.html.eex:10 #: lib/block_scout_web/templates/tokens/instance/overview/_tabs.html.eex:10
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:72 #: lib/block_scout_web/views/tokens/instance/overview_view.ex:73
msgid "Metadata" msgid "Metadata"
msgstr "" msgstr ""

@ -14,7 +14,7 @@ defmodule BlockScoutWeb.ApiDocsViewTest do
test "adds slash before path" do test "adds slash before path" do
Application.put_env(:block_scout_web, BlockScoutWeb.Endpoint, Application.put_env(:block_scout_web, BlockScoutWeb.Endpoint,
url: [scheme: "https", host: "blockscout.com", port: 9999, path: "/chain/dog"] url: [scheme: "https", host: "blockscout.com", port: 9999, api_path: "/chain/dog"]
) )
assert APIDocsView.api_url() == "https://blockscout.com/chain/dog/api" assert APIDocsView.api_url() == "https://blockscout.com/chain/dog/api"
@ -22,7 +22,7 @@ defmodule BlockScoutWeb.ApiDocsViewTest do
test "does not add slash to empty path" do test "does not add slash to empty path" do
Application.put_env(:block_scout_web, BlockScoutWeb.Endpoint, Application.put_env(:block_scout_web, BlockScoutWeb.Endpoint,
url: [scheme: "https", host: "blockscout.com", port: 9999, path: ""] url: [scheme: "https", host: "blockscout.com", port: 9999, api_path: ""]
) )
assert APIDocsView.api_url() == "https://blockscout.com/api" assert APIDocsView.api_url() == "https://blockscout.com/api"
@ -49,7 +49,7 @@ defmodule BlockScoutWeb.ApiDocsViewTest do
test "adds slash before path" do test "adds slash before path" do
Application.put_env(:block_scout_web, BlockScoutWeb.Endpoint, Application.put_env(:block_scout_web, BlockScoutWeb.Endpoint,
url: [scheme: "https", host: "blockscout.com", port: 9999, path: "/chain/dog"] url: [scheme: "https", host: "blockscout.com", port: 9999, api_path: "/chain/dog"]
) )
assert APIDocsView.eth_rpc_api_url() == "https://blockscout.com/chain/dog/api/eth_rpc" assert APIDocsView.eth_rpc_api_url() == "https://blockscout.com/chain/dog/api/eth_rpc"

Loading…
Cancel
Save