Skip to content

Instantly share code, notes, and snippets.

@bheeshmar
Created February 7, 2012 22:28
Show Gist options
  • Save bheeshmar/1762576 to your computer and use it in GitHub Desktop.
Save bheeshmar/1762576 to your computer and use it in GitHub Desktop.
Webserver for Textaid Chrome plugin
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