Sha256: 6c3ab70e7e6b574f65ac1a0a9d5cb8baa351289f517d74be362361b2ad502775
Contents?: true
Size: 990 Bytes
Versions: 4
Compression:
Stored size: 990 Bytes
Contents
require "em-websocket" require "eventmachine" module Mado class Server def self.run(options) EM.kqueue = true if EM.kqueue? EM.run do sockets = [] host = options[:host] || "0.0.0.0" port = options[:port] || "8080" debug = options[:debug] || false markdown_path = options[:markdown] EM.watch_file(markdown_path, Mado::FileHandler, sockets) EM::WebSocket.start(host: host, port: 8081, debug: debug) do |ws| ws.onopen do ws.send(Mado::Markdown.convert_markdown(markdown_path)) sockets << ws unless sockets.include?(ws) end ws.onclose do sockets.delete(ws) end end app = Rack::Builder.app do map "/" do run Mado::App end end Rack::Server.start(app: app, Host: host, Port: port) trap("TERM") { EM.stop } trap("INT") { EM.stop } end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
mado-0.0.4 | lib/mado/server.rb |
mado-0.0.3 | lib/mado/server.rb |
mado-0.0.2 | lib/mado/server.rb |
mado-0.0.1 | lib/mado/server.rb |