Skip to content

Commit

Permalink
BYO Domains: Enforce Custom Domains when Set
Browse files Browse the repository at this point in the history
#74
#1078

This doesn't compeltely fix #1078, but it should help with making sure
the branded domains take precedence (which is part of the problem)
  • Loading branch information
zspencer committed Jan 30, 2023
1 parent 5e00038 commit fb0b048
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# Default controller for new resources; ensures requests fulfill authentication
# and authorization requirements, as well as exposes common helper methods.
class ApplicationController < ActionController::Base
before_action :ensure_on_byo_domain


include Pundit::Authorization
after_action :verify_authorized
after_action :verify_policy_scoped
Expand Down Expand Up @@ -64,6 +67,18 @@ class ApplicationController < ActionController::Base
super
end


# @todo this should be tested 🙃 halp me
def ensure_on_byo_domain
if request.get? && current_space.branded_domain.present? && request.domain != current_space.branded_domain

redirect_url = URI(request.url)
redirect_url.host = current_space.branded_domain
redirect_url.path = redirect_url.path.gsub("/spaces/#{current_space.slug}","")
redirect_to redirect_url.to_s, allow_other_host: true
end
end

private

OPERATOR_TOKEN = ENV["OPERATOR_API_KEY"]
Expand Down

0 comments on commit fb0b048

Please sign in to comment.