New option to set application name (#606)

This commit is contained in:
Aravinda Vishwanathapura 2021-04-05 20:35:06 +05:30 committed by GitHub
parent 3fee068636
commit de5e022222
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 4 deletions

View File

@ -58,4 +58,11 @@ describe "Config" do
it "gets the version from shards.yml" do
Kemal::VERSION.should_not be("")
end
it "sets application name" do
config = Kemal.config
config.app_name.should eq "Kemal"
config.app_name = "testapp"
config.app_name.should eq "testapp"
end
end

View File

@ -67,11 +67,11 @@ module Kemal
def self.display_startup_message(config, server)
addresses = server.addresses.join ", " { |address| "#{config.scheme}://#{address}" }
log "[#{config.env}] Kemal is ready to lead at #{addresses}"
log "[#{config.env}] #{config.app_name} is ready to lead at #{addresses}"
end
def self.stop
raise "Kemal is already stopped." if !config.running
raise "#{Kemal.config.app_name} is already stopped." if !config.running
if server = config.server
server.close unless server.closed?
config.running = false
@ -90,7 +90,7 @@ module Kemal
private def self.setup_trap_signal
Signal::INT.trap do
log "Kemal is going to take a rest!" if Kemal.config.shutdown_message
log "#{Kemal.config.app_name} is going to take a rest!" if Kemal.config.shutdown_message
Kemal.stop
exit
end

View File

@ -24,9 +24,10 @@ module Kemal
property always_rescue, server : HTTP::Server?, extra_options, shutdown_message
property serve_static : (Bool | Hash(String, Bool))
property static_headers : (HTTP::Server::Response, String, File::Info -> Void)?
property powered_by_header : Bool = true
property powered_by_header : Bool = true, app_name
def initialize
@app_name = "Kemal"
@host_binding = "0.0.0.0"
@port = 3000
@env = ENV["KEMAL_ENV"]? || "development"