kemalcr / kemal

Fast, Effective, Simple Web Framework
https://kemalcr.com
MIT License
3.62k stars 188 forks source link

Adding Handlers #664

Closed RainbowZephyr closed 7 months ago

RainbowZephyr commented 1 year ago

Hello, This is not an issue per se, I just wanted to know if it is possible to add handlers programmatically during the server initialization. I tried doing the following but it was not working:

Kemal.run do |config|        
       config.add_handler(MyHandler.new)
       server = config.server.not_nil!
end

Am I initializing the handler wrong?

Thanks in advance

straight-shoota commented 1 year ago

At the point where the block executes, kemal has already setup all handlers (calling config.setup). Thus, adding handlers afterwards in the run block won't have any effect.

It should be possible before calling Kemal.run, though.

Kemal.config.add_handler(MyHandler.new)
Kemal.run do |config|
  server = config.server.not_nil!
end
Sija commented 7 months ago

This can be closed it seems.