class Opal::CliRunners::Server
def build_app(source)
def build_app(source) app = App.new(source) if static_folder not_found = [404, {}, []] app = Rack::Cascade.new( [ Rack::Static.new(->(_) { not_found }, urls: [''], root: static_folder), app ], ) end app end
def exit_status
def exit_status nil end
def initialize(options)
def initialize(options) @output = options.fetch(:output, $stdout) @port = options.fetch(:port, ENV['OPAL_CLI_RUNNERS_SERVER_PORT'] || 3000).to_i @static_folder = options[:static_folder] || ENV['OPAL_CLI_RUNNERS_SERVER_STATIC_FOLDER'] @static_folder = @static_folder == true ? 'public' : @static_folder @static_folder = File.expand_path(@static_folder) if @static_folder end
def run(source, argv)
def run(source, argv) unless argv.empty? raise ArgumentError, 'Program arguments are not supported on the Server runner' end require 'rack' require 'webrick' require 'logger' app = build_app(source) @server = Rack::Server.start( app: app, Port: port, AccessLog: [], Logger: Logger.new(output), ) end