Created
February 7, 2012 22:28
-
-
Save bheeshmar/1762576 to your computer and use it in GitHub Desktop.
Webserver for Textaid Chrome plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'webrick' | |
include WEBrick | |
# Start gvim in foreground mode | |
$EDITOR = "gvim -f" | |
class FileUploadServlet < HTTPServlet::AbstractServlet | |
def do_POST(req, res) | |
filedata = req.body | |
# TODO: Use tempfile instead of foo.out. | |
File.open("foo.out", "wb") do |f| | |
f.syswrite(filedata) | |
end | |
system($EDITOR + " foo.out") | |
res.body = File.read("foo.out") | |
end | |
end | |
s = HTTPServer.new( | |
:Port => 9292, | |
#:Logger => Log.new(nil, BasicLog::WARN), | |
:AccessLog => [], | |
:DocumentRoot => Dir.pwd) | |
s.mount("/", FileUploadServlet) | |
trap("INT") { s.shutdown } | |
puts 'Starting' | |
s.start | |
puts 'Bye' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment