Last active
December 20, 2017 20:12
-
-
Save devdiva/7187030 to your computer and use it in GitHub Desktop.
1-liners for Ruby local servers (not rails). I use these for tutorials, quick access to demo front-end code, etc.
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
# | |
# The simplest one liners are using ruby/lib/un.rb methods. | |
# | |
# @n0kada and @tenderlove's one liner is darn simple, but doesn't play nice with my OSX's ruby 1.8.7 defaults. | |
# Set your local rubies to 1.9.3 or greater (which you should be running anyway) and it's all good. | |
ruby -run -e httpd . -p 5000 | |
# | |
# Starts WEBrick (works for me with 1.8.7 and up) | |
# The more verbose one liners are running webrick and executing some command line scripts. | |
# These are pretty verbose for a 1-liner and a sign you should consider using a script file. | |
# | |
# Starts WEBrick | |
# This won't work unless you have a handler for "/" | |
ruby -rwebrick -e'WEBrick::HTTPServer.new(:Port => 3000).start' | |
# Starts WEBrick with directory listing | |
ruby -rwebrick -e'WEBrick::HTTPServer.new(:Port => 3000, :DocumentRoot => Dir.pwd).start' | |
# Starts WEBrick with directory listing and svg support | |
# This version adds mime-type handler for SVG so we can select *.svg from directory listing and view in the browser | |
ruby -rwebrick -e'my_mime_types = WEBrick::HTTPUtils::DefaultMimeTypes; my_mime_types.store("svg","image/svg+xml");WEBrick::HTTPServer.new(:Port => 3000, :DocumentRoot => Dir.pwd, :mime_types =>my_mime_types).start' | |
# This version adds mime-type handler for web fonts | |
ruby -rwebrick -e'my_mime_types = WEBrick::HTTPUtils::DefaultMimeTypes; my_mime_types.store("ttf","application/x-font-ttf"); my_mime_types.store("otf","application/x-font-opentype"); my_mime_types.store("svg","image/svg+xml");WEBrick::HTTPServer.new(:Port => 5000, :DocumentRoot => Dir.pwd, :mime_types =>my_mime_types).start' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment