Created
October 2, 2012 18:22
-
-
Save greyblake/3822028 to your computer and use it in GitHub Desktop.
Serg server
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
#!/usr/bin/env ruby | |
require 'cgi' | |
# Refresh period | |
PERIOD = 1 # seconds | |
# Calculate random value from 1 to 10 | |
value = rand(10) + 1 | |
# Create CGI object | |
cgi = CGI.new('html4') | |
# Build HTML ouput with CGI DSL. | |
cgi.out do | |
cgi.head do | |
cgi.meta('http-equiv' => 'refresh', 'content' => PERIOD.to_s) | |
end + | |
cgi.html do | |
cgi.body do | |
cgi.p { "value = #{value}" } | |
end | |
end | |
end | |
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' | |
# Current directory | |
root = File.dirname(__FILE__) | |
# Initialize server with port and DocumentRoot dir | |
server = WEBrick::HTTPServer.new :Port => 8000, :DocumentRoot => root | |
# Set signal handler to shutdown server when you press Ctrl+C | |
trap 'INT' do server.shutdown end | |
# Run server on 8000 port | |
server.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
index.cgi
be executable: runchmod +x ./index.cgi
ruby ./server.rb
http://localhost:8000