chore: drop FRONTEND_URL_EXTERNAL var

This commit is contained in:
gabrieljablonski 2025-05-02 20:44:10 -03:00
parent 1100260620
commit add11d29c1
8 changed files with 14 additions and 22 deletions

View File

@ -258,9 +258,6 @@ 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,7 +1,7 @@
module FrontendUrlsHelper
def frontend_url(path, **query_params)
url_params = query_params.blank? ? '' : "?#{query_params.to_query}"
host = ENV.fetch('FRONTEND_URL_EXTERNAL', root_url)
host = ENV.fetch('FRONTEND_URL', root_url)
host = "#{host}/" unless host.end_with?('/')
"#{host}app/#{path}#{url_params}"
end

View File

@ -54,6 +54,10 @@ class Channel::Whatsapp < ApplicationRecord
end
end
def use_internal_host?
provider == 'baileys' && ENV.fetch('BAILEYS_PROVIDER_USE_INTERNAL_HOST_URL', false)
end
def mark_message_templates_updated
# rubocop:disable Rails/SkipsModelValidations
update_column(:message_templates_last_updated, Time.zone.now)

View File

@ -159,15 +159,17 @@ class Inbox < ApplicationRecord
end
def callback_webhook_url
host = ENV.fetch('FRONTEND_URL', nil)
case channel_type
when 'Channel::TwilioSms'
"#{ENV.fetch('FRONTEND_URL', nil)}/twilio/callback"
"#{host}/twilio/callback"
when 'Channel::Sms'
"#{ENV.fetch('FRONTEND_URL', nil)}/webhooks/sms/#{channel.phone_number.delete_prefix('+')}"
"#{host}/webhooks/sms/#{channel.phone_number.delete_prefix('+')}"
when 'Channel::Line'
"#{ENV.fetch('FRONTEND_URL', nil)}/webhooks/line/#{channel.line_channel_id}"
"#{host}/webhooks/line/#{channel.line_channel_id}"
when 'Channel::Whatsapp'
"#{ENV.fetch('FRONTEND_URL', nil)}/webhooks/whatsapp/#{channel.phone_number}"
host = ENV.fetch('INTERNAL_HOST_URL', nil) if channel.use_internal_host?
"#{host}/webhooks/whatsapp/#{channel.phone_number}"
end
end

View File

@ -34,8 +34,7 @@ Rails.application.configure do
config.active_job.queue_adapter = :sidekiq
host = ENV['FRONTEND_URL_EXTERNAL'].presence || ENV['FRONTEND_URL']
Rails.application.routes.default_url_options = { host: host }
Rails.application.routes.default_url_options = { host: ENV['FRONTEND_URL'] }
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log

View File

@ -102,6 +102,5 @@ Rails.application.configure do
# :sendgrid for Sendgrid
config.action_mailbox.ingress = ENV.fetch('RAILS_INBOUND_EMAIL_SERVICE', 'relay').to_sym
host = ENV['FRONTEND_URL_EXTERNAL'].presence || ENV['FRONTEND_URL']
Rails.application.routes.default_url_options = { host: host }
Rails.application.routes.default_url_options = { host: ENV['FRONTEND_URL'] }
end

View File

@ -50,8 +50,7 @@ Rails.application.configure do
# config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "chatwoot_#{Rails.env}"
host = ENV['FRONTEND_URL_EXTERNAL'].presence || ENV['FRONTEND_URL']
Rails.application.routes.default_url_options = { host: host }
Rails.application.routes.default_url_options = { host: ENV['FRONTEND_URL'] }
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).

View File

@ -13,13 +13,5 @@ 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