|
Revision 2071, 0.9 kB
(checked in by tokuhirom, 5 years ago)
|
|
lang/ruby/ssb: WebrickServlet? としてやったら構成がスッキリするんじゃね & Webrick で動かいたときに高速になるんじゃね??という気がしたのでそうしてみた。気にくわなかったら revert しやってくだしあ
|
| Line | |
|---|
| 1 | require 'webrick' |
|---|
| 2 | require 'optparse' |
|---|
| 3 | |
|---|
| 4 | port = 10080 |
|---|
| 5 | bind_address = '127.0.0.1' |
|---|
| 6 | cgi_mode = false |
|---|
| 7 | |
|---|
| 8 | opt = OptionParser.new |
|---|
| 9 | opt.on('-p port', '--port port') {|v| port = v.to_i } |
|---|
| 10 | opt.on('--bind ip') {|v| bind_address = v } |
|---|
| 11 | opt.on('--cgi-mode') {|v| cgi_mode = true } # only for debugging? |
|---|
| 12 | opt.parse!(ARGV) |
|---|
| 13 | |
|---|
| 14 | bindir = File.dirname(__FILE__) |
|---|
| 15 | docroot = File.expand_path(File.join(bindir, 'public_html')) |
|---|
| 16 | Dir.chdir(docroot) |
|---|
| 17 | require '../config/common.rb' |
|---|
| 18 | require 'ssb.rb' |
|---|
| 19 | |
|---|
| 20 | srv = WEBrick::HTTPServer.new({ |
|---|
| 21 | :DocumentRoot => docroot, |
|---|
| 22 | :BindAddress => bind_address, |
|---|
| 23 | :Port => port, |
|---|
| 24 | }) |
|---|
| 25 | trap("INT"){ srv.shutdown } |
|---|
| 26 | |
|---|
| 27 | if cgi_mode |
|---|
| 28 | srv.mount('/', WEBrick::HTTPServlet::CGIHandler, File.join(docroot, 'index.rbx')) |
|---|
| 29 | else |
|---|
| 30 | srv.mount_proc('/') {|req, res| |
|---|
| 31 | app = SSB::Application.new |
|---|
| 32 | app.run(req, res) |
|---|
| 33 | } |
|---|
| 34 | end |
|---|
| 35 | |
|---|
| 36 | %w(javascripts stylesheets emoji images).each {|x| |
|---|
| 37 | srv.mount("/#{x}/", WEBrick::HTTPServlet::FileHandler, File.join(docroot, x)) |
|---|
| 38 | } |
|---|
| 39 | srv.start |
|---|
| 40 | |
|---|