Method: Command::Web#execute

Defined in:
lib/command/web.rb

#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"