Skip to content

Instantly share code, notes, and snippets.

@mushtat
Last active March 24, 2016 13:29
Show Gist options
  • Save mushtat/35589ff98987481384ad to your computer and use it in GitHub Desktop.
Save mushtat/35589ff98987481384ad to your computer and use it in GitHub Desktop.
Ruby simple web-server with webrick
require 'webrick'
config = {
'port' => 3002
}
server = WEBrick::HTTPServer.new({:Port => config['port']})
server.mount_proc '/' do |request, response|
filename = request.path.sub! '/', ''
if File.exist?(request.path)
result = File.read(request.path)
else
result = 'Custom error page content'
end
response.body = result
end
trap("INT") {
server.shutdown
}
server.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment