Last active
August 29, 2015 14:06
-
-
Save wulab/0bac5050b856012855b5 to your computer and use it in GitHub Desktop.
Running Servlets 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
<pre> | |
Request to <%= servlet_request.request_uri %> | |
Query params <%= servlet_request.query.inspect %> | |
</pre> |
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' | |
include WEBrick | |
server = HTTPServer.new(Port: 8000) | |
# Add a mime type for *.rhtml files | |
HTTPUtils::DefaultMimeTypes.store('rhtml', 'text/html') | |
# Required for CGI on Windows; unnecessary on Unix/Linux | |
server.config.store(:CGIInterpreter, HTTPServlet::CGIHandler::Ruby) | |
# Mount servlets | |
server.mount('/', HTTPServlet::FileHandler, '.') | |
# Trap signals so as to shutdown cleanly | |
['TERM', 'INT'].each do |signal| | |
trap(signal) { server.shutdown } | |
end | |
# Start the server and block on input | |
server.start |
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
#!/bin/sh | |
ruby -rwebrick -e 'WEBrick::Config::HTTP[:MimeTypes]["rhtml"] = "text/html"' -run -e httpd -- -p 8000 . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment