Class: Gemite::HttpServer
- Inherits:
-
Object
- Object
- Gemite::HttpServer
- Defined in:
- lib/gemite/http_server.rb
Overview
依存ゼロ(Ruby標準の socket のみ)で実装した小規模開発用HTTPサーバ。 .gmt ファイルはリクエストごとに読み直してパース・実行するため、 編集内容が即座に反映される(再起動不要)。
Instance Method Summary collapse
-
#initialize(root:, port: 8000, host: "0.0.0.0") ⇒ HttpServer
constructor
A new instance of HttpServer.
- #start ⇒ Object
Constructor Details
#initialize(root:, port: 8000, host: "0.0.0.0") ⇒ HttpServer
Returns a new instance of HttpServer.
15 16 17 18 19 20 |
# File 'lib/gemite/http_server.rb', line 15 def initialize(root:, port: 8000, host: "0.0.0.0") @root = File.(root) @port = port @host = host @router = Router.new(@root) end |
Instance Method Details
#start ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gemite/http_server.rb', line 22 def start $stdout.sync = true server = TCPServer.new(@host, @port) puts "Gemite dev server listening on http://localhost:#{@port}" puts "root: #{@root}" puts "(Ctrl-C で停止)" trap("INT") do puts "\nシャットダウンします..." exit(0) end loop do client = server.accept Thread.new(client) { |c| handle_client(c) } end end |