Fix definitions of NETWORK_PATH, API_PATH, SOKCET_ROOT: process trailing slash

pull/6357/head
Viktor Baranov 2 years ago
parent cd4572804c
commit 50487be827
  1. 5
      apps/block_scout_web/assets/js/socket.js
  2. 22
      apps/block_scout_web/config/config.exs
  3. 6
      apps/block_scout_web/config/prod.exs
  4. 3
      apps/block_scout_web/lib/block_scout_web/controllers/account/auth_controller.ex
  5. 2
      apps/block_scout_web/lib/block_scout_web/router.ex
  6. 2
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/contract.ex
  7. 20
      apps/explorer/lib/explorer/repo/config_helper.ex
  8. 4
      config/runtime/dev.exs

@ -2,9 +2,12 @@ import { Socket } from 'phoenix'
import { locale } from './locale' import { locale } from './locale'
let websocketRootUrl = process.env.SOCKET_ROOT let websocketRootUrl = process.env.SOCKET_ROOT
if (!websocketRootUrl || websocketRootUrl === '/') { if (!websocketRootUrl) {
websocketRootUrl = '' websocketRootUrl = ''
} }
if (websocketRootUrl.endsWith('/')) {
websocketRootUrl = websocketRootUrl.slice(0, -1)
}
const socket = new Socket(websocketRootUrl + '/socket', { params: { locale } }) const socket = new Socket(websocketRootUrl + '/socket', { params: { locale } })
socket.connect() socket.connect()

@ -5,6 +5,24 @@
# is restricted to this project. # is restricted to this project.
import Config import Config
network_path =
"NETWORK_PATH"
|> System.get_env("/")
|> (&(if !String.ends_with?(&1, "/") do
&1 <> "/"
else
&1
end)).()
api_path =
"API_PATH"
|> System.get_env("/")
|> (&(if !String.ends_with?(&1, "/") do
&1 <> "/"
else
&1
end)).()
# General application configuration # General application configuration
config :block_scout_web, config :block_scout_web,
namespace: BlockScoutWeb, namespace: BlockScoutWeb,
@ -18,8 +36,8 @@ config :block_scout_web, BlockScoutWeb.Counters.BlocksIndexedCounter, enabled: t
# Configures the endpoint # Configures the endpoint
config :block_scout_web, BlockScoutWeb.Endpoint, config :block_scout_web, BlockScoutWeb.Endpoint,
url: [ url: [
path: System.get_env("NETWORK_PATH") || "/", path: network_path,
api_path: System.get_env("API_PATH") || "/" api_path: api_path
], ],
render_errors: [view: BlockScoutWeb.ErrorView, accepts: ~w(html json)], render_errors: [view: BlockScoutWeb.ErrorView, accepts: ~w(html json)],
pubsub_server: BlockScoutWeb.PubSub pubsub_server: BlockScoutWeb.PubSub

@ -15,11 +15,7 @@ import Config
# which you typically run after static files are built. # which you typically run after static files are built.
config :block_scout_web, BlockScoutWeb.Endpoint, config :block_scout_web, BlockScoutWeb.Endpoint,
cache_static_manifest: "priv/static/cache_manifest.json", cache_static_manifest: "priv/static/cache_manifest.json",
force_ssl: false, force_ssl: false
url: [
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

@ -3,6 +3,7 @@ defmodule BlockScoutWeb.Account.AuthController do
alias BlockScoutWeb.Models.UserFromAuth alias BlockScoutWeb.Models.UserFromAuth
alias Explorer.Account alias Explorer.Account
alias Explorer.Repo.ConfigHelper
alias Plug.CSRFProtection alias Plug.CSRFProtection
plug(Ueberauth) plug(Ueberauth)
@ -68,6 +69,6 @@ defmodule BlockScoutWeb.Account.AuthController do
def current_user(_), do: nil def current_user(_), do: nil
defp root do defp root do
System.get_env("NETWORK_PATH") || "/" ConfigHelper.network_path()
end end
end end

@ -64,7 +64,7 @@ defmodule BlockScoutWeb.Router do
path = url_params[:path] path = url_params[:path]
if path != api_path do if path != api_path do
scope to_string(api_path) <> "/verify_smart_contract" do scope to_string(api_path) <> "verify_smart_contract" do
pipe_through(:api) pipe_through(:api)
post("/contract_verifications", BlockScoutWeb.AddressContractVerificationController, :create) post("/contract_verifications", BlockScoutWeb.AddressContractVerificationController, :create)

@ -219,6 +219,8 @@ defmodule EthereumJSONRPC.Contract do
end end
end end
defp format_error(nil), do: {:error, ""}
defp format_error(message) when is_binary(message) do defp format_error(message) when is_binary(message) do
{:error, message} {:error, message}
end end

@ -57,4 +57,24 @@ defmodule Explorer.Repo.ConfigHelper do
end end
end) end)
end end
def network_path do
path = System.get_env("NETWORK_PATH", "/")
path_from_env(path)
end
def api_path do
path = System.get_env("API_PATH", "/")
path_from_env(path)
end
defp path_from_env(path_env_var) do
if String.ends_with?(path_env_var, "/") do
path_env_var
else
path_env_var <> "/"
end
end
end end

@ -22,9 +22,7 @@ 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") || "/",
api_path: System.get_env("API_PATH") || "/"
], ],
https: [ https: [
port: (port && port + 1) || 4001, port: (port && port + 1) || 4001,

Loading…
Cancel
Save