Class: Portless::Multi

Inherits:
Object
  • Object
show all
Includes:
RunSupport
Defined in:
lib/portless/multi.rb

Overview

Run several apps under one proxy, each at its own <name>.<tld>, from the apps map in portless.json. Every app gets a free backend port, a route, and injected PORT/HOST/PORTLESS_URL; all run in their own process groups and are supervised + torn down together. Ruby sets env per-spawn, so there's no NODE_OPTIONS loader hack (cf. portless's turbo.ts).

Defined Under Namespace

Classes: App

Instance Method Summary collapse

Constructor Details

#initialize(config: Config.load, route_store: RouteStore.new) ⇒ Multi

Returns a new instance of Multi.



14
15
16
17
18
# File 'lib/portless/multi.rb', line 14

def initialize(config: Config.load, route_store: RouteStore.new)
  @config = config
  @route_store = route_store
  @apps = []
end

Instance Method Details

#runObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/portless/multi.rb', line 20

def run
  raise Error, "no apps defined — add an \"apps\" map to portless.json" if @config.apps.empty?

  ensure_trusted
  proxy_port = Daemon.ensure_running(tls: @config.tls)
  @apps = @config.apps.map { |name, command| start_app(name, command, proxy_port) }

  Banner.multi(apps: @apps)
  install_signal_handlers
  Process.waitall
ensure
  teardown
end