Class: Async::App::WebServer
- Inherits:
-
Object
- Object
- Async::App::WebServer
- Includes:
- Component
- Defined in:
- lib/async/app/web_server.rb
Defined Under Namespace
Classes: Router
Constant Summary collapse
- APP_ADDED =
"async-app.web_app.added"
Instance Method Summary collapse
- #add_app(app) ⇒ Object
- #after_init ⇒ Object
-
#initialize(port: 8080) ⇒ WebServer
constructor
A new instance of WebServer.
- #run! ⇒ Object
Methods included from Component
#after_run, included, #init!, #start!, #stop!
Constructor Details
#initialize(port: 8080) ⇒ WebServer
Returns a new instance of WebServer.
22 23 24 25 |
# File 'lib/async/app/web_server.rb', line 22 def initialize(port: 8080) @router = Router.new @endpoint = Async::HTTP::Endpoint.parse("http://0.0.0.0:#{port}") end |
Instance Method Details
#add_app(app) ⇒ Object
29 |
# File 'lib/async/app/web_server.rb', line 29 def add_app(app) = @router.add(app) |
#after_init ⇒ Object
27 |
# File 'lib/async/app/web_server.rb', line 27 def after_init = bus.subscribe(APP_ADDED) { add_app(_1) } |
#run! ⇒ Object
31 32 33 34 |
# File 'lib/async/app/web_server.rb', line 31 def run! Async { Async::HTTP::Server.new(@router, @endpoint).run } info { "Started on #{@endpoint.url}" } end |