-
Notifications
You must be signed in to change notification settings - Fork 1
/
dev.rb
executable file
·46 lines (39 loc) · 1.15 KB
/
dev.rb
1
2
3
4
5
6
7
8
9
10
11
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
40
41
42
43
44
45
46
#!/usr/bin/env ruby
# Runs the CGI script at http://localhost:3101/
# with datadir at thisdir/data, and log to stderr.
require 'webrick'
Dir.chdir(File.dirname($0))
project_dir = Dir.pwd
port = 3101
cgi_program = project_dir + '/cgi-bin/tmc-spyware-server-cgi'
data_dir = project_dir + '/data'
auth_url = 'http://localhost:3000/auth.text'
$extra_env_vars = {
'TMC_SPYWARE_DATA_DIR' => data_dir,
'TMC_SPYWARE_AUTH_URL' => auth_url
}
# We need terrible hax to smuggle our envvars through to WEBrick's CGI handler :(
module MyCGIHandlerBuilder
def self.get_instance(server, *options)
handler = WEBrick::HTTPServlet::CGIHandler.get_instance(server, *options)
class << handler
def do_GET(req, res)
class << req
def meta_vars
mv = super
mv.merge($extra_env_vars)
end
end
super(req, res)
end
alias do_POST do_GET # Need to realias
end
handler
end
end
server = WEBrick::HTTPServer.new(:Port => port, :DocumentRoot => 'cgi-bin', :AccessLog => [])
server.mount('/', MyCGIHandlerBuilder, File.expand_path(cgi_program))
trap("INT") do
server.shutdown
end
server.start