Use URL_HOST if provided

This commit is contained in:
Jamil Bou Kheir
2021-12-29 06:24:08 -06:00
parent 38cce9d54c
commit 86b50596b9
3 changed files with 15 additions and 2 deletions

View File

@@ -133,14 +133,14 @@
<div class="level-left">
<code id="shareable-link">
<%= if @device.config_token do %>
<%= Routes.device_url(@socket, :config, @device.config_token) %>
<%= shareable_link(@socket, @device) %>
<% end %>
</code>
</div>
<div class="level-right">
<%= if @device.config_token do %>
<button id="copy-shareable-link-button"
data-clipboard={Routes.device_url(@socket, :config, @device.config_token)}
data-clipboard={shareable_link(@socket, @device)}
data-target="shareable-link"
class="button"
data-tooltip="Click to copy"

View File

@@ -7,6 +7,7 @@ defmodule FzHttpWeb.LiveHelpers do
import Phoenix.LiveView
import Phoenix.LiveView.Helpers
alias FzHttp.Users
alias FzHttpWeb.Router.Helpers, as: Routes
import FzHttpWeb.ControllerHelpers, only: [root_path_for_role: 1]
@@ -63,6 +64,17 @@ defmodule FzHttpWeb.LiveHelpers do
end
end
@doc """
URL_HOST is used in releases to set an externally-accessible url. Use that if exists.
"""
def shareable_link(socket, device) do
if url_host = Application.get_env(:fz_http, :url_host) do
"https://" <> url_host <> Routes.device_path(socket, :config, device.config_token)
else
Routes.device_url(socket, :config, device.config_token)
end
end
defp status_digit(response_code) when is_integer(response_code) do
[status_digit | _tail] = Integer.digits(response_code)
status_digit

View File

@@ -92,6 +92,7 @@ config :fz_vpn,
cli: FzVpn.CLI.Live
config :fz_http,
url_host: url_host,
connectivity_checks_enabled: connectivity_checks_enabled,
connectivity_checks_interval: connectivity_checks_interval,
admin_email: admin_email,