From 5befcc92e0cfc53042ebad2e244dc653818775c9 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Thu, 7 Nov 2024 15:28:19 -0600 Subject: [PATCH] ActionCable: working again --- app/channels/application_cable/connection.rb | 2 +- app/channels/export_channel.rb | 2 +- app/javascript/channels/export_channel.js | 6 +++--- app/javascript/channels/index.js | 11 +++++++---- app/javascript/entrypoints/application.js | 4 +++- config/cable.yml | 13 ++++++------- config/environments/development.rb | 4 ++-- config/routes.rb | 4 ++-- 8 files changed, 25 insertions(+), 21 deletions(-) diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb index 2c84e59bf..e59083764 100644 --- a/app/channels/application_cable/connection.rb +++ b/app/channels/application_cable/connection.rb @@ -20,4 +20,4 @@ def find_verified_user end end end -end +end \ No newline at end of file diff --git a/app/channels/export_channel.rb b/app/channels/export_channel.rb index 742084409..ee9bf4b5f 100644 --- a/app/channels/export_channel.rb +++ b/app/channels/export_channel.rb @@ -9,4 +9,4 @@ def subscribed def unsubscribed # Any cleanup needed when channel is unsubscribed end -end +end \ No newline at end of file diff --git a/app/javascript/channels/export_channel.js b/app/javascript/channels/export_channel.js index b58579644..dffe121b7 100644 --- a/app/javascript/channels/export_channel.js +++ b/app/javascript/channels/export_channel.js @@ -3,16 +3,16 @@ import consumer from "./consumer" consumer.subscriptions.create({ channel: "ExportChannel" }, { connected() { // Called when the subscription is ready for use on the server - console.log('Export Channel Connected'); + console.log("GBL Admin - ExportChannel connected"); }, disconnected() { // Called when the subscription has been terminated by the server - console.log('Export Channel Disconnected'); + console.log("GBL Admin - ExportChannel disconnected"); }, received(data) { - console.log('Export Channel Received'); + console.log('GBL Admin - ExportChannel received!'); console.log(data); if (data['progress']) { diff --git a/app/javascript/channels/index.js b/app/javascript/channels/index.js index 0cfcf7491..e95ecec1c 100644 --- a/app/javascript/channels/index.js +++ b/app/javascript/channels/index.js @@ -1,5 +1,8 @@ -// Load all the channels within this directory and all subdirectories. -// Channel files must be named *_channel.js. +// Function to dynamically import all channel files +async function importAllChannels() { + const modules = import.meta.glob('./*_channel.js'); + const importPromises = Object.keys(modules).map(path => modules[path]()); + await Promise.all(importPromises); +} -const channels = require.context('.', true, /_channel\.js$/) -channels.keys().forEach(channels) +importAllChannels(); diff --git a/app/javascript/entrypoints/application.js b/app/javascript/entrypoints/application.js index 619e35528..86b2c713f 100644 --- a/app/javascript/entrypoints/application.js +++ b/app/javascript/entrypoints/application.js @@ -22,7 +22,9 @@ console.log('Vite ⚡️ Rails') // ActiveStorage.start() // // // Import all channels. -// const channels = import.meta.globEager('./**/*_channel.js') +import '../channels/consumer' +import '../channels/export_channel' +import '../channels/index' // Example: Import a stylesheet in app/frontend/index.css // import '~/index.css' diff --git a/config/cable.yml b/config/cable.yml index 232fc5be8..b03f164f4 100644 --- a/config/cable.yml +++ b/config/cable.yml @@ -1,10 +1,9 @@ +# config/cable.yml +production: + adapter: postgresql + development: - adapter: async + adapter: postgresql test: - adapter: async - -production: - adapter: redis - url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> - channel_prefix: geoblacklight_production + adapter: postgresql \ No newline at end of file diff --git a/config/environments/development.rb b/config/environments/development.rb index 3d3f7f715..a80ac11cc 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -64,12 +64,12 @@ # Raises error for missing translations. # config.i18n.raise_on_missing_translations = true - # config.active_job.queue_adapter = :inline config.active_job.queue_adapter = :sidekiq + Redis.exists_returns_integer = true # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true # Uncomment if you wish to allow Action Cable access from any origin. - # config.action_cable.disable_request_forgery_protection = true + config.action_cable.disable_request_forgery_protection = true end diff --git a/config/routes.rb b/config/routes.rb index c5668b2b1..7155d4afa 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ Rails.application.routes.draw do + mount ActionCable.server => "/cable" + get 'about', :to => redirect('https://gin.btaa.org/') get 'help', :to => redirect('https://gin.btaa.org/guides/') get 'robots.:format' => 'robots#robots' @@ -297,8 +299,6 @@ # @TODO # mount Qa::Engine => "/authorities" - mount ActionCable.server => "/cable" - # @TODO authenticate :user, ->(user) { user } do mount Blazer::Engine, at: "blazer"