Git Product home page Git Product logo

logux-rack's Introduction

Sponsored by Amplifr

Logux::Rack

Build Status Coverage Status

Add WebSockets, live-updates and offline-first to any Rack-based application with Logux. It adds Logux Back-end Protocol support to Ruby on Rails or any other Rack applications, so you can use Logux Server as a proxy between WebSocket and your web application.

Read Creating Logux Proxy guide.

Installation

Add this line to your application's Gemfile:

gem 'logux-rack'

And then execute:

bundle

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

After checking out the repo, run:

docker-compose run app bundle install

Run tests with:

docker-compose run app bundle exec rspec

Run RuboCop with:

docker-compose run app bundle exec rubocop

License

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.