Project

companion

0.0
The project is in a healthy, maintained state
Companion is a mountable engine that spawns and supervises companion applications.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

>= 0
>= 0
 Project Readme

Companion

Companion is a mountable Rails engine for running a companion application (e.g. Node, Python, Go, etc.) alongside a Rails application. Companion spawns and supervises the process, then proxies traffic from a mounted path in your Rails routes to the spawned process.

Usage

Installation

Gemfile

gem "companion"
bundle install

Configuration

Initialize your application via a an initializer (e.g. config/initializers/companion.rb):

# config/initializers/companion.rb
Companion.configure do |config|
  config.app :dashboard do |app|
    app.command = -> { |port| "npm run serve -- --port {port}" }
    app.directory = Rails.root.join("dashboard")
    app.environment = { "NODE_ENV" => Rails.env.production? ? "production" : "development" }
  end
end

Routing

Mount your application as an engine in config/routes.rb:

# config/routes.rb
Rails.application.routes.draw do
  mount Companion::Engine.app(:dashboard), at: "/dashboard"
end

Examples

companions/greeter/Gemfile

source "https://rubygems.org"

gemspec

gem "rack"

companions/greeter/config.ru

# companions/greeter/config.ru

run do |env|
  [200, { "content-type" => "text/plain" }, ["Greetings!"]]
end

config/initializers/companion.rb

Companion.configure do |config|
  config.app :greeter do |app|
    app.command = -> { |port| "rackup --port #{port}" }
    app.directory = Rails.root.join("companions", "greeter")
  end
end

config/routes.rb

Rails.application.routes.draw do
  mount Companion::Engine.app(:greeter), at: "/greeter"
end
rails server
curl --verbose https://localhost:3000/greeter