Newer
Older
about-Leaflet / web.rb
@SugawaraMiyu SugawaraMiyu on 18 Jun 2024 733 bytes 見本
#!/usr/bin/env ruby
# 設置方法:
#	1. 新規にディレクトリを作る: 例:
#		cd Ruby
#		mkdir cgi
#		cd cgi
#	2. 作成したディレクトリ(例では ~/Ruby/cgi)に web.rb hello.rb を保存する
#	3. 実行属性をつける
#		chmod +x web.rb hello.rb
#	4. 起動する:
#		./web.rb
#	5. ブラウザでつなぐ:
#		http://localhost:3000/hello.rb
require 'webrick'
include WEBrick

module WEBrick::HTTPServlet
  FileHandler.add_handler('rb', CGIHandler)
  FileHandler.add_handler('sh', CGIHandler)
  FileHandler.add_handler('cgi', CGIHandler)
end

s = HTTPServer.new(
  :Port => (ENV["PORT"]||3000),
  :DocumentRoot => ENV["DOCROOT"]||".",
  :DirectoryIndex => ["hello.rb"]
)
trap("INT") { s.shutdown }
s.start