Last Updated: September 09, 2019
·
1.231K
· blazeeboy

Creating a HTTP Server with ruby in 7 LOC

i usually face a problem, while being an instructor for ruby on rails i want to share files with audience, so flash stick or memroy card is not optional, and all of them downloading the file from the internet would take ages with our egyptian lines speed, so i fire up this script and let them enter to my IP address and download the files to their machines :)

require 'webrick'

Port = 3000
Directory = Dir::pwd

WEBrick::HTTPServer.new(
    Port: Port,
    DocumentRoot: Directory
).start

4 Responses
Add your response

With Femtows : 2 lines, ans add some
get('/path') { code }

over 1 year ago ·

:) i have seen it today, good job Raubarede, i like it.

over 1 year ago ·

How about with one line?

ruby -run -e httpd . -p 3000

:)

over 1 year ago ·

yup, that works like charm :D, thanks

over 1 year ago ·