Skip to content

Commit

Permalink
ActionCable: working again
Browse files Browse the repository at this point in the history
  • Loading branch information
ewlarson committed Nov 7, 2024
1 parent d0ad56f commit 5befcc9
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion app/channels/application_cable/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ def find_verified_user
end
end
end
end
end
2 changes: 1 addition & 1 deletion app/channels/export_channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ def subscribed
def unsubscribed
# Any cleanup needed when channel is unsubscribed
end
end
end
6 changes: 3 additions & 3 deletions app/javascript/channels/export_channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']) {
Expand Down
11 changes: 7 additions & 4 deletions app/javascript/channels/index.js
Original file line number Diff line number Diff line change
@@ -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();
4 changes: 3 additions & 1 deletion app/javascript/entrypoints/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
13 changes: 6 additions & 7 deletions config/cable.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -297,8 +299,6 @@

# @TODO
# mount Qa::Engine => "/authorities"
mount ActionCable.server => "/cable"

# @TODO
authenticate :user, ->(user) { user } do
mount Blazer::Engine, at: "blazer"
Expand Down

0 comments on commit 5befcc9

Please sign in to comment.