Class: Command::Web
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from CommandBase
execute!, #force_change_settings_function, help, #hook_call, #load_local_settings, #tagname_to_ids
Constructor Details
#initialize ⇒ Web
Returns a new instance of Web.
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/command/web.rb', line 12
def initialize
super("[options...]")
@opt.separator "\n \u30FBWEB\u30A2\u30D7\u30EA\u30B1\u30FC\u30B7\u30E7\u30F3\u7528\u30B5\u30FC\u30D0\u3092\u8D77\u52D5\u3057\u307E\u3059\n \u30FB\u5C0F\u8AAC\u306E\u7BA1\u7406\u53CA\u3073\u8A2D\u5B9A\u3092\u30D6\u30E9\u30A6\u30B6\u3067\u884C\u3046\u3053\u3068\u304C\u3067\u304D\u307E\u3059\n \u30FB--port \u3092\u6307\u5B9A\u3057\u306A\u3044\u5834\u5408\u3001\u30DD\u30FC\u30C8\u306F\u521D\u56DE\u8D77\u52D5\u6642\u306B\u30E9\u30F3\u30C0\u30E0\u3067\u8A2D\u5B9A\u3057\u307E\u3059\n(\u4EE5\u964D\u540C\u3058\u8A2D\u5B9A\u3092\u5F15\u304D\u7D99\u304E\u307E\u3059)\n \u30FB\u30B5\u30FC\u30D0\u8D77\u52D5\u5F8C\u306B\u30D6\u30E9\u30A6\u30B6\u3092\u7ACB\u3061\u4E0A\u3052\u307E\u3059\n \u30FB\u30B5\u30FC\u30D0\u306E\u505C\u6B62\u306F\u30B3\u30F3\u30BD\u30FC\u30EB\u3067 Ctrl+C \u3092\u5165\u529B\u3057\u307E\u3059\n\n Examples:\nnarou web # \u30B5\u30FC\u30D0\u8D77\u52D5(\u30DD\u30FC\u30C8\u306F\u30E9\u30F3\u30C0\u30E0\u3002\u30DD\u30FC\u30C8\u8A2D\u5B9A\u4FDD\u5B58)\nnarou web -p 4567 # \u30DD\u30FC\u30C84567\u3067\u8D77\u52D5(\u4FDD\u5B58\u306F\u3055\u308C\u306A\u3044)\n\n# \u5148\u306B\u6C7A\u3081\u3066\u304A\u304F\nnarou s server-port=8000\nnarou web # \u30DD\u30FC\u30C88000\u3067\u8D77\u52D5\n\n Options:\n EOS\n @opt.on(\"-p\", \"--port PORT\", Integer, \"\u8D77\u52D5\u3059\u308B\u30DD\u30FC\u30C8\u3092\u6307\u5B9A\") { |port|\n @options[\"port\"] = port\n }\n @opt.on(\"-n\", \"--no-browser\", \"\u8D77\u52D5\u6642\u306B\u30D6\u30E9\u30A6\u30B6\u306F\u958B\u304B\u306A\u3044\") {\n @options[\"no-browser\"] = true\n }\nend\n"
|
Class Method Details
.oneline_help ⇒ Object
8
9
10
|
# File 'lib/command/web.rb', line 8
def self.oneline_help
"WEBアプリケーション用サーバを起動します"
end
|
Instance Method Details
#confirm_of_first ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/command/web.rb', line 41
def confirm_of_first
setting = Inventory.load("server_setting", :global)
is_first = !setting["already-server-boot"]
if is_first
puts "\u521D\u3081\u3066\u30B5\u30FC\u30D0\u3092\u8D77\u52D5\u3057\u307E\u3059\u3002\u30D5\u30A1\u30A4\u30A2\u30A6\u30A9\u30FC\u30EB\u306E\u30A2\u30AF\u30BB\u30B9\u8A31\u53EF\u3092\u5C0B\u306D\u3089\u308C\u305F\u5834\u5408\u3001\u8A31\u53EF\u3092\u3057\u3066\u4E0B\u3055\u3044\u3002\n\u307E\u305F\u3001\u8D77\u52D5\u3057\u305F\u30B5\u30FC\u30D0\u3092\u6B62\u3081\u308B\u306B\u306F\u30B3\u30F3\u30BD\u30FC\u30EB\u4E0A\u3067 Ctrl+C \u3092\u5165\u529B\u3059\u308B\u304B\u3001\u30D6\u30E9\u30A6\u30B6\u4E0A\u3067\u300C\u8A2D\u5B9A(\u6B6F\u8ECA\u30DE\u30FC\u30AF)\u2192\u30B5\u30FC\u30D0\u3092\u30B7\u30E3\u30C3\u30C8\u30C0\u30A6\u30F3\u300D\u3092\u5B9F\u884C\u3057\u3066\u4E0B\u3055\u3044\u3002\n\n EOS\n if @options[\"no-browser\"]\n puts \"(\u4F55\u304B\u30AD\u30FC\u3092\u62BC\u3057\u3066\u4E0B\u3055\u3044)\"\n else\n puts \"(\u4F55\u304B\u30AD\u30FC\u3092\u62BC\u3057\u3066\u4E0B\u3055\u3044\u3002\u30B5\u30FC\u30D0\u8D77\u52D5\u5F8C\u30D6\u30E9\u30A6\u30B6\u304C\u7ACB\u3061\u4E0A\u304C\u308A\u307E\u3059)\"\n end\n $stdin.getch\n setting[\"already-server-boot\"] = true\n setting.save\n end\n is_first\nend\n"
|
#create_push_server(params) ⇒ Object
62
63
64
65
66
67
68
69
|
# File 'lib/command/web.rb', line 62
def create_push_server(params)
host, port = params[:host], params[:port]
push_server = Narou::PushServer.instance
push_server.accepted_domains = (host == "0.0.0.0" ? "*" : host)
push_server.port = port + 1
push_server.host = host
push_server
end
|
#execute(argv) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/command/web.rb', line 71
def execute(argv)
super
require_relative "../web/all"
confirm_of_first
params = Narou::AppServer.create_address(@options["port"])
push_server = create_push_server(params)
Narou.web = true
Thread.abort_on_exception = true
address = "http://#{params[:host]}:#{params[:port]}/"
puts address
puts "サーバを止めるには Ctrl+C を入力"
puts
push_server.run
unless @options["no-browser"]
Thread.new do
sleep 0.2 until Narou::AppServer.running?
Helper.open_browser(address)
end
end
$stdout = Narou::StreamingLogger.new(push_server)
ProgressBar.push_server = push_server
Narou::AppServer.push_server = push_server
Narou::Worker.instance.start
Narou::AppServer.run!
push_server.quit
rescue Errno::EADDRINUSE => e
Helper.open_browser(address) unless @options["no-browser"]
STDOUT.puts "\#{e}\n\u30DD\u30FC\u30C8\u304C\u4F7F\u308F\u308C\u3066\u3044\u307E\u3059\u3002\u30B5\u30FC\u30D0\u304C\u3059\u3067\u306B\u7ACB\u3061\u4E0A\u304C\u3063\u3066\u3044\u308B\u304B\u3069\u3046\u304B\u78BA\u8A8D\u3057\u3066\u4E0B\u3055\u3044\u3002\n\u4ED6\u306E\u30A2\u30D7\u30EA\u30B1\u30FC\u30B7\u30E7\u30F3\u304C\u4F7F\u3063\u3066\u3044\u308B\u30DD\u30FC\u30C8\u3060\u3063\u305F\u5834\u5408\u3001\u30DD\u30FC\u30C8\u3092\u5909\u66F4\u3057\u3066\u4E0B\u3055\u3044\u3002\n\n\u30DD\u30FC\u30C8\u306E\u5909\u66F4\u65B9\u6CD5\n $ narou s server-port=5678\n EOS\n exit Narou::EXIT_ERROR_CODE\nend\n"
|