multi tenant with custom domain on rails

后端 未结 2 1273
野性不改
野性不改 2021-02-01 11:31

I\'m creating a multi tenant application like shopify and wanna know how can I create custom domain on server that points to the same application instance? For example:

2条回答
  •  迷失自我
    2021-02-01 11:52

    I have a similar setup and am using nginX. What I did for ease of maintenance was accepted all the connections from nginx and did the filtering in my app.

    # application_controller.rb
    before_filter :current_client
    
    private
    def current_client
      # I am using MongoDB with Mongoid, so change the syntax of query accordingly
      @current_client ||= Client.where(:host => request.host).first
      render('/public/404.html', :status => :not_found, :layout => false) unless @current_client
    end
    

    You can have your clients have a domain record with there domain/subdomain pointing to you_ip or your_domain_pointing_to_your_ip.com and capture that in a form and save in database. Then alter the query in current_client like:

    @current_client ||= Client.or(:host => request.host).or(:alias => request.host).first
    

提交回复
热议问题