From 137dc813d9da683e9bf055948d92cb54d021a1ab Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Mon, 8 Jul 2019 09:56:47 +0300 Subject: [PATCH] parse url for api docs --- .../lib/block_scout_web/views/api_docs_view.ex | 4 +++- .../block_scout_web/views/api_docs_view_test.exs | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 apps/block_scout_web/test/block_scout_web/views/api_docs_view_test.exs diff --git a/apps/block_scout_web/lib/block_scout_web/views/api_docs_view.ex b/apps/block_scout_web/lib/block_scout_web/views/api_docs_view.ex index f9c280925a..aca1ba558d 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/api_docs_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/api_docs_view.ex @@ -36,7 +36,9 @@ defmodule BlockScoutWeb.APIDocsView do def blockscout_url 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 Endpoint.url() end diff --git a/apps/block_scout_web/test/block_scout_web/views/api_docs_view_test.exs b/apps/block_scout_web/test/block_scout_web/views/api_docs_view_test.exs new file mode 100644 index 0000000000..3c2634d22b --- /dev/null +++ b/apps/block_scout_web/test/block_scout_web/views/api_docs_view_test.exs @@ -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