From 1e38ebcd51a5c704a9d6672eb176d963f421a243 Mon Sep 17 00:00:00 2001 From: Yan Date: Fri, 18 May 2018 11:15:25 +0630 Subject: [PATCH] update cable --- app/assets/javascripts/cable.js | 6 ++++++ app/assets/javascripts/channels/order.js | 2 -- app/channels/application_cable/connection.rb | 20 ++++++++++++++++++++ config/initializers/action_controller.rb | 10 +++++----- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/cable.js b/app/assets/javascripts/cable.js index 55bfd46b..033f521b 100755 --- a/app/assets/javascripts/cable.js +++ b/app/assets/javascripts/cable.js @@ -9,6 +9,12 @@ (function() { this.App || (this.App = {}); + // var hostname = location.hostname; + // var port = location.port; + // var host = hostname + ":" + port + "/cable" + // console.log(host); + // App.cable = ActionCable.createConsumer(); + // console.log(App.cable); App.cable = ActionCable.createConsumer(); }).call(this); diff --git a/app/assets/javascripts/channels/order.js b/app/assets/javascripts/channels/order.js index 9598ed6f..26c7897e 100755 --- a/app/assets/javascripts/channels/order.js +++ b/app/assets/javascripts/channels/order.js @@ -1,6 +1,4 @@ App.order = App.cable.subscriptions.create('OrderChannel', { -// App.messages = App.cable.subscriptions.create('MessagesChannel', { - connected: function() {}, disconnected: function() {}, diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb index 4efdb70d..14561a4e 100755 --- a/app/channels/application_cable/connection.rb +++ b/app/channels/application_cable/connection.rb @@ -1,7 +1,27 @@ module ApplicationCable class Connection < ActionCable::Connection::Base + identified_by :current_subdomain def connect + if ENV["server_mode"] == "cloud" + self.current_subdomain = verified_subdomain + end logger.add_tags "SX-ActionCable" end + + private + def verified_subdomain + from = request.subdomain.downcase + "." + request.domain.downcase + file_path = "config/shops.json" + shop_data = File.read(file_path) + + shop_json = JSON.parse(shop_data) + shop_json["data"].each do |j| + if j["lookup"] == from + verified_subdomain = from + else + reject_unauthorized_connection + end + end + end end end diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index e0eb7455..b84bca54 100644 --- a/config/initializers/action_controller.rb +++ b/config/initializers/action_controller.rb @@ -20,11 +20,11 @@ class ActionController::Base end else #check for license file - if check_license - current_license(ENV["SX_PROVISION_URL"]) - else - redirect_to activate_path - end + # if check_license + # current_license(ENV["SX_PROVISION_URL"]) + # else + # redirect_to activate_path + # end end end