chore: add support for external frontend URL in environment configuration

This commit is contained in:
gabrieljablonski 2025-04-01 23:59:07 -03:00
parent 5b7fc9ae77
commit 0348d0b25a
3 changed files with 13 additions and 1 deletions

View File

@ -258,6 +258,9 @@ AZURE_APP_SECRET=
# contact_inboxes with no conversation older than 90 days will be removed
# REMOVE_STALE_CONTACT_INBOX_JOB_STATUS=false
# NOTE: Useful when running inside docker-compose network to link to external domain
FRONTEND_URL_EXTERNAL=
# Baileys API Whatsapp provider
BAILEYS_PROVIDER_DEFAULT_CLIENT_NAME=Chatwoot
BAILEYS_PROVIDER_DEFAULT_URL=http://localhost:3025

View File

@ -1,6 +1,7 @@
module FrontendUrlsHelper
def frontend_url(path, **query_params)
url_params = query_params.blank? ? '' : "?#{query_params.to_query}"
"#{root_url}app/#{path}#{url_params}"
host = ENV.fetch('FRONTEND_URL_EXTERNAL', root_url)
"#{host}app/#{path}#{url_params}"
end
end

View File

@ -13,5 +13,13 @@ describe FrontendUrlsHelper do
expect(helper.frontend_url('dashboard', p1: 'p1', p2: 'p2')).to eq 'http://test.host/app/dashboard?p1=p1&p2=p2'
end
end
context 'with set FRONTEND_URL_EXTERNAL' do
it 'creates path correctly' do
with_modified_env 'FRONTEND_URL_EXTERNAL' => 'http://external.url/' do
expect(helper.frontend_url('dashboard')).to eq 'http://external.url/app/dashboard'
end
end
end
end
end