diff --git a/app/controllers/conferences_controller.rb b/app/controllers/conferences_controller.rb index 53e5bd6d..15a59a0c 100644 --- a/app/controllers/conferences_controller.rb +++ b/app/controllers/conferences_controller.rb @@ -9,10 +9,17 @@ class ConferencesController < ApplicationController @antiquated = @conferences - @current end - def show; end + def show + # have to change "localhost" to ENV['OSEM_HOSTNAME'] in production + check_custom_domain if request.host != 'localhost' + end private + def check_custom_domain + @conference = @conference.custom_domain.present? ? Conference.find_by(custom_domain: request.domain) : @conference + end + def respond_to_options respond_to do |format| format.html { head :ok } diff --git a/config/initializers/domain_constraint.rb b/config/initializers/domain_constraint.rb new file mode 100644 index 00000000..67e19a75 --- /dev/null +++ b/config/initializers/domain_constraint.rb @@ -0,0 +1,6 @@ +class DomainConstraint + def self.matches?(request) + @domains = Conference.pluck(:custom_domain).compact + @domains.include?(request.domain) + end +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 5a17d314..381e55ee 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,9 @@ Osem::Application.routes.draw do + constraints DomainConstraint do + get '/', to: 'conferences#show' + end + if ENV['OSEM_ICHAIN_ENABLED'] == 'true' devise_for :users, controllers: { registrations: :registrations } else diff --git a/db/migrate/20170721184810_add_custom_domain_to_conferences.rb b/db/migrate/20170721184810_add_custom_domain_to_conferences.rb new file mode 100644 index 00000000..d5aef4fd --- /dev/null +++ b/db/migrate/20170721184810_add_custom_domain_to_conferences.rb @@ -0,0 +1,5 @@ +class AddCustomDomainToConferences < ActiveRecord::Migration + def change + add_column :conferences, :custom_domain, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index d49dfa03..797c1930 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,10 +11,10 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170721001700) do +ActiveRecord::Schema.define(version: 20170721184810) do create_table "ahoy_events", force: :cascade do |t| - t.integer "visit_id" + t.uuid "visit_id", limit: 16 t.integer "user_id" t.string "name" t.text "properties" @@ -127,6 +127,7 @@ ActiveRecord::Schema.define(version: 20170721001700) do t.integer "end_hour", default: 20 t.integer "organization_id" t.integer "ticket_layout", default: 0 + t.string "custom_domain" end add_index "conferences", ["organization_id"], name: "index_conferences_on_organization_id"