cli: add ability to bind to custom addr / port
This commit is contained in:
parent
3ab0106d11
commit
d72b9597f0
3 changed files with 19 additions and 9 deletions
|
@ -3,6 +3,16 @@
|
|||
class Twenty::Command::Up < Twenty::Command
|
||||
set_banner usage: "twenty up [OPTIONS]",
|
||||
description: "Start the twenty web server"
|
||||
set_option "-b ADDR",
|
||||
"--bind ADDR",
|
||||
"Bind to ADDR (default: 127.0.0.1)",
|
||||
default: "127.0.0.1"
|
||||
set_option "-p PORT",
|
||||
"--port PORT",
|
||||
"Listen on PORT (default: 2020)",
|
||||
default: 2020,
|
||||
as: Integer
|
||||
|
||||
include CommonOptionMixin
|
||||
prepend Twenty::Command::MigrationMixin
|
||||
prepend Twenty::Command::SQLiteMixin
|
||||
|
@ -15,7 +25,7 @@ class Twenty::Command::Up < Twenty::Command
|
|||
private
|
||||
|
||||
def run_command(options)
|
||||
server = Twenty::Servlet.server
|
||||
server = Twenty::Servlet.server(options)
|
||||
trap(:SIGINT) { server.shutdown }
|
||||
server.start
|
||||
end
|
||||
|
|
|
@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
|
|||
gem.summary = "twenty: CLI component"
|
||||
gem.description = gem.summary
|
||||
gem.executables = ["twenty", "20"]
|
||||
gem.add_runtime_dependency "cmd.rb", "~> 0.2"
|
||||
gem.add_runtime_dependency "cmd.rb", "~> 0.4"
|
||||
gem.add_development_dependency "test-unit", "~> 3.5.7"
|
||||
gem.add_development_dependency "yard", "~> 0.9"
|
||||
gem.add_development_dependency "redcarpet", "~> 3.5"
|
||||
|
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
module Twenty::Servlet::ServerMixin
|
||||
##
|
||||
# @param [Hash] options
|
||||
# Server options that take precedence over
|
||||
# @param [Hash] cli_options
|
||||
# CLI options merged into
|
||||
# {ServerMixin#server_options ServerMixin#server_options}.
|
||||
#
|
||||
# @return [WEBrick::HTTPServer]
|
||||
# Returns an instance of WEBrick::HTTPServer.
|
||||
def server(options = {})
|
||||
server = WEBrick::HTTPServer.new server_options.merge(options)
|
||||
def server(cli_options = {})
|
||||
server = WEBrick::HTTPServer.new server_options(cli_options)
|
||||
server.mount "/graphql", Twenty::Servlet::GraphQL
|
||||
server
|
||||
end
|
||||
|
@ -17,11 +17,11 @@ module Twenty::Servlet::ServerMixin
|
|||
##
|
||||
# @return [Hash<Symbol, String>]
|
||||
# The default server options given to WEBrick::HTTPServer.new.
|
||||
def server_options
|
||||
def server_options(cli_options)
|
||||
{
|
||||
DocumentRoot: Twenty.build,
|
||||
BindAddress: "127.0.0.1",
|
||||
Port: 2020
|
||||
BindAddress: cli_options.bind,
|
||||
Port: cli_options.port
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue