From d747bd98700dd8b015ef48e8a2a1df0025012b0a Mon Sep 17 00:00:00 2001 From: eugenijm Date: Fri, 1 Feb 2019 21:56:18 +0300 Subject: [PATCH 1/2] Use String.replace_leading instead of String.replace for getting websocket streaming api url. Extract the login responsible for obtaining websocket URL into the corresponding Endpoint function. --- lib/pleroma/web/endpoint.ex | 4 ++++ lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/endpoint.ex b/lib/pleroma/web/endpoint.ex index 2b156fdfd..ebbc5d7b5 100644 --- a/lib/pleroma/web/endpoint.ex +++ b/lib/pleroma/web/endpoint.ex @@ -82,4 +82,8 @@ def load_from_system_env(config) do port = System.get_env("PORT") || raise "expected the PORT environment variable to be set" {:ok, Keyword.put(config, :http, [:inet6, port: port])} end + + def websocket_url do + String.replace_leading(static_url(), "http", "ws") + end end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index a94eb5c73..85769c3d7 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -138,7 +138,7 @@ def masto_instance(conn, _params) do version: "#{@mastodon_api_level} (compatible; #{Pleroma.Application.named_version()})", email: Keyword.get(instance, :email), urls: %{ - streaming_api: String.replace(Pleroma.Web.Endpoint.static_url(), "http", "ws") + streaming_api: Pleroma.Web.Endpoint.websocket_url() }, stats: Stats.get_stats(), thumbnail: Web.base_url() <> "/instance/thumbnail.jpeg", From a184811a605a56436cc5b9eae8ef5c3834285922 Mon Sep 17 00:00:00 2001 From: eugenijm Date: Fri, 1 Feb 2019 22:35:19 +0300 Subject: [PATCH 2/2] Use url() instead of static_url in Endpoint.websocket_url() --- lib/pleroma/web/endpoint.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/endpoint.ex b/lib/pleroma/web/endpoint.ex index ebbc5d7b5..3eed047ca 100644 --- a/lib/pleroma/web/endpoint.ex +++ b/lib/pleroma/web/endpoint.ex @@ -84,6 +84,6 @@ def load_from_system_env(config) do end def websocket_url do - String.replace_leading(static_url(), "http", "ws") + String.replace_leading(url(), "http", "ws") end end