mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Added Frank::Config
This commit is contained in:
parent
a1c8a1b6f1
commit
69ed2d4612
2 changed files with 34 additions and 9 deletions
20
src/frank.cr
20
src/frank.cr
|
@ -2,21 +2,23 @@ require "option_parser"
|
|||
require "./frank/*"
|
||||
|
||||
$frank_handler = Frank::Handler.new
|
||||
port = 3000
|
||||
|
||||
OptionParser.parse! do |opts|
|
||||
opts.on("-p ", "--port ", "port") do |opt_port|
|
||||
port = opt_port.to_i
|
||||
end
|
||||
end
|
||||
|
||||
at_exit do
|
||||
OptionParser.parse! do |opts|
|
||||
opts.on("-p ", "--port ", "port") do |opt_port|
|
||||
Frank.config.port = opt_port.to_i
|
||||
end
|
||||
end
|
||||
|
||||
config = Frank.config
|
||||
handlers = [] of HTTP::Handler
|
||||
handlers << HTTP::LogHandler.new
|
||||
handlers << HTTP::StaticFileHandler.new("./public")
|
||||
handlers << $frank_handler
|
||||
server = HTTP::Server.new(port, handlers)
|
||||
server = HTTP::Server.new(config.port, handlers)
|
||||
|
||||
puts "Listening on http://0.0.0.0:#{port}"
|
||||
server.ssl = config.ssl
|
||||
|
||||
puts "Listening on #{config.scheme}://0.0.0.0:#{config.port}"
|
||||
server.listen
|
||||
end
|
||||
|
|
23
src/frank/config.cr
Normal file
23
src/frank/config.cr
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Frank
|
||||
class Config
|
||||
INSTANCE = Config.new
|
||||
property ssl
|
||||
property port
|
||||
|
||||
def initialize
|
||||
@port = 3000
|
||||
end
|
||||
|
||||
def scheme
|
||||
ssl ? "https" : "http"
|
||||
end
|
||||
end
|
||||
|
||||
def self.config
|
||||
yield Config::INSTANCE
|
||||
end
|
||||
|
||||
def self.config
|
||||
Config::INSTANCE
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue