parse url for api docs

pull/2310/head
Ayrat Badykov 5 years ago
parent 2a9b34b70e
commit 137dc813d9
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 4
      apps/block_scout_web/lib/block_scout_web/views/api_docs_view.ex
  2. 14
      apps/block_scout_web/test/block_scout_web/views/api_docs_view_test.exs

@ -36,7 +36,9 @@ defmodule BlockScoutWeb.APIDocsView do
def blockscout_url do def blockscout_url do
if System.get_env("BLOCKSCOUT_HOST") do if System.get_env("BLOCKSCOUT_HOST") do
"http://" <> System.get_env("BLOCKSCOUT_HOST") %URI{host: host, scheme: scheme} = URI.parse(Endpoint.url())
scheme <> "://" <> host
else else
Endpoint.url() Endpoint.url()
end end

@ -0,0 +1,14 @@
defmodule BlockScoutWeb.ApiDocsViewTest do
use BlockScoutWeb.ConnCase, async: true
alias BlockScoutWeb.{APIDocsView, Endpoint}
describe "blockscout_url/0" do
test "returns url with scheme and host without port" do
System.put_env("BLOCKSCOUT_HOST", "localhost")
assert APIDocsView.blockscout_url() == "http://localhost"
assert Endpoint.url() == "http://localhost:4002"
end
end
end
Loading…
Cancel
Save