Project

logux-rack

0.03
No release in over 3 years
Low commit activity in last 3 years
There's a lot of open issues
This gem provides building blocks to integrate Logux server interaction features into a Rack-based web applications.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.16
>= 0
>= 0
~> 10.0
~> 3.8
~> 0.60.0
~> 1.27.0

Runtime

>= 0
~> 2.0
>= 1.7.3, < 3
>= 2.0, < 3
 Project Readme
Sponsored by Amplifr

Logux::Rack

This gem provides Logux back-end protocol support for Rack-based applications, including Ruby on Rails. It enables Logux Server integration for full-duplex client-server communication.

Installation

Add this line to your application's Gemfile:

gem 'logux-rack'

And then execute:

bundle install

Usage

Here is a minimal Rack configuration to start new Logux::Rack server:

# config.ru
require 'logux/rack'

run Logux.application

Note that the HTTP response streaming depends on the web server used to serve the application. Use a server with streaming capability. Puma, for instance:

gem install puma

Start the server:

puma config.ru

It is possible to mount Logux::Rack server within an existing Rails application. First of all, you will need to configure Logux by defining a server address in an initializer. For example, config/initializers/logux.rb:

Logux.configuration do |config|
  config.logux_host = 'http://localhost:31338'
end

Mount Logux::Rack in routes:

Rails.application.routes.draw do
  mount Logux::Rack::App => '/'
end

After this, POST requests to /logux will be processed by LoguxController. You can redefine it or inherit from, if it necessary, for example, for implementing custom authorization flow.

Here is another routing example for Roda application routing:

class MyApp < Roda
  route do |r|
    r.is 'logux' { r.run Logux::Rack::App }
  end
end

Hanami configuration example:

# config/environment.rb
Hanami.configure do
  mount Logux::Rack::App, at: '/'
end

Logux::Rack can also be embedded into another Rack application using Rack::Builder:

# config.ru
require 'logux/rack'

app = Rack::Builder.new do
  use Rack::CommonLogger
  map '/logux' { run Logux::Rack::App }
  # ...
end

run app

Logux::Rack will try to find Action for the specific message from Logux Server. For example, for project/rename action, you should define Action::Project class, inherited from Logux::Action base class, and implement rename method.

You can execute rake logux:actions to get the list of available action types, or rake logux:channels to get the list of available channels. Use optional path parameter to limit the search scope: rake logux:actions[lib/logux/actions]

Development with Docker

Install gem dependencies:

docker-compose run app bundle install

Run the specs:

docker-compose run app bundle exec rspec

Perform integration test:

cd test/app
bundle exec rails db:reset && bundle exec rails server

# Execute from another terminal:
cd test
yarn && npx @logux/backend-test http://server:3000/logux

Run Rubocop:

docker-compose run app bundle exec rubocop

License

The gem is available as open source under the terms of the MIT License.