server.rb 508 Bytes
Newer Older
Paweł Chojnacki's avatar
Paweł Chojnacki committed
1
require 'webrick'
Joshua Lambert's avatar
Joshua Lambert committed
2
require 'securerandom'
Paweł Chojnacki's avatar
Paweł Chojnacki committed
3
4
5

server = WEBrick::HTTPServer.new :Port => 5000

Joshua Lambert's avatar
Joshua Lambert committed
6
#Return a successful Hello World response.
Paweł Chojnacki's avatar
Paweł Chojnacki committed
7
server.mount_proc '/' do |request, response|
Joshua Lambert's avatar
Joshua Lambert committed
8
  response.body = 'Hello, world!'
Joshua Lambert's avatar
Joshua Lambert committed
9
  sleep 0.125 + SecureRandom.random_number*0.250
Joshua Lambert's avatar
Joshua Lambert committed
10
11
end

Joshua Lambert's avatar
Joshua Lambert committed
12
#Return an error to help demonstrate monitoring capabilities
Joshua Lambert's avatar
Joshua Lambert committed
13
14
15
16
server.mount_proc '/error' do |request, response|
  response.status = 500
  response.body = 'Sorry we encountered an error.'
  sleep 1.0+SecureRandom.random_number
Paweł Chojnacki's avatar
Paweł Chojnacki committed
17
end
Paweł Chojnacki's avatar
Paweł Chojnacki committed
18
19

server.start