kemalcr / kemal

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

Add server property of a whole application #396

Closed vladfaust closed 6 years ago

vladfaust commented 7 years ago

Currently #run forces the server to start listening, whilst the server can be used as a mountable server with HTTP::Multiserver.

Please add a separate method #server to Kemal:

def server(port = 0)
  @server ||= HTTP::Server.new(port) # Whatever the initialization code is
end

so a user can mount Kemal apps like this:

app = MyKemalApp.server
sidekiq = Sidekiq::Web.server

HTTP::Multiserver.new(port, {
  "/sidekiq" => sidekiq, 
  "/"        => app
}).listen

This is a missing feature of Crystal which holds lots of potential developers from switching to it.

ghost commented 7 years ago

add it to official git it will be great,i also spend time on it,making wheels is not good

sdogruyol commented 7 years ago

There's already an option for this Kemal.config.server =, isn't that enough?

vladfaust commented 6 years ago

@sdogruyol yep, config has server property, but it's useless due to this line: https://github.com/kemalcr/kemal/blob/8cf3f67594394665db2b17f9675ca38fbf427ef5/src/kemal.cr#L35

Basically, you can get server only after Kemal.run, and it blocks the thread, am I right?

I propose changing the line above to config.server ||= HTTP::Server.new(config.host_binding, config.port, config.handlers), so a developer could setup the server before Kemal is run.