Last active
March 24, 2016 13:29
-
-
Save mushtat/35589ff98987481384ad to your computer and use it in GitHub Desktop.
Ruby simple web-server with webrick
This file contains 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' | |
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