Skip to content

Instantly share code, notes, and snippets.

@ono-max
Created October 18, 2022 00:05
Show Gist options
  • Save ono-max/4995066f3a16eb0084721886720a6100 to your computer and use it in GitHub Desktop.
Save ono-max/4995066f3a16eb0084721886720a6100 to your computer and use it in GitHub Desktop.
require 'webrick'
require 'json'
binding = TOPLEVEL_BINDING.dup
srv = WEBrick::HTTPServer.new({:BindAddress => '127.0.0.1',
:Port => 8080})
srv.mount_proc('/') {|req, res|
body = JSON.parse req.body
expr = body['expression']
result = binding.eval(expr)
puts result
res.body = JSON.generate({result: result})
}
srv.mount_proc('/files') {|req, res|
body = JSON.parse req.body
text = body['text']
file = Tempfile.create(%w[debug- .rb])
file.write(text)
file.close
res.body = JSON.generate({path: file.path})
}
srv.mount_proc('/debug') {|req, res|
body = JSON.parse req.body
Thread.new do
end
pid = Process.fork {
b = binding.eval("load '#{body['path']}'")
}
res.body = JSON.generate({})
}
Signal.trap(:INT){ srv.shutdown }
srv.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment