Lightweight Ruby Webserver to list podcasts

Once you get your head around ruby constructs the following was easy to write:

As a benefit it actually displays properly…

require ‘socket’

def latest3podcasts(session, podcast)
session.print “

  • Dir.glob(podcast)[-3..-1].each {|x| session.print “
  • #{x}
  • ” }
    session.print “


port = 8080.to_i
server =‘serveraddress’,port)
while (session = server.accept)
puts “Request: #{session.gets}”
session.print “HTTP/1.1 200/OKrnContent-type: text/htmlrnrn”
session.print “”
latest3podcasts(session, “/storage/podcast/dotnetrocks/*.mp3”)
latest3podcasts(session, “/storage/podcast/hanselminutes/*.mp3”)
latest3podcasts(session, “/storage/podcast/polymorphicpodcast/*.mp3”)
session.print “rn”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s