-
-
Save DouglasAllen/b0b5c254c60eec44b7d9 to your computer and use it in GitHub Desktop.
Simple ruby webserver
This file contains hidden or 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' | |
| require 'erb' | |
| template = <<TEMPLATE | |
| <html> | |
| <head> | |
| <title>Ruby as PHP</title> | |
| </head> | |
| <body> | |
| <h1>Loop</h1> | |
| <% 1.upto(5).each do |i| %> | |
| <p>Number <%= i %></p> | |
| <% end %> | |
| </body> | |
| TEMPLATE | |
| server = WEBrick::HTTPServer.new :Port => 8081 | |
| server.mount_proc '/' do |req, res| | |
| res.body = ERB.new(template).result(binding) | |
| end | |
| trap 'INT' do server.shutdown end | |
| server.start |
Author
DouglasAllen
commented
Aug 15, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment