Class: FunApi::Server::Falcon
- Inherits:
-
Object
- Object
- FunApi::Server::Falcon
- Defined in:
- lib/funapi/server/falcon.rb
Overview
Falcon server adapter - uses protocol-rack for proper Rack integration
Class Method Summary collapse
Class Method Details
.start(app, host: "0.0.0.0", port: 3000) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/funapi/server/falcon.rb', line 10 def self.start(app, host: "0.0.0.0", port: 3000) Async do |task| falcon_app = Protocol::Rack::Adapter.new(app) endpoint = ::Async::HTTP::Endpoint.parse("http://#{host}:#{port}").with(protocols: Async::HTTP::Protocol::HTTP2) server = ::Falcon::Server.new(falcon_app, endpoint) app.run_startup_hooks if app.respond_to?(:run_startup_hooks) puts "Falcon listening on #{host}:#{port}" puts "Try: curl http://#{host}:#{port}/hello" puts "Press Ctrl+C to stop" shutdown = -> { puts "\nShutting down..." app.run_shutdown_hooks if app.respond_to?(:run_shutdown_hooks) task.stop exit } trap(:INT) { shutdown.call } trap(:TERM) { shutdown.call } server.run end end |