Tay Ray Chuan home archive

serve me up

Tue, 20 Aug 2013 02:04:07 +0800 | Filed under node.js, python, ruby, recipe

Serving out static files shouldn't require creating a VirtualHost in Apache or a nginx config file (this project may not be render this claim inaccurate though). Here's how to do it in one line.

Ruby

$ ruby -run -e httpd . -p8000

In true dsl fashion, this requires the un standard library (-run), and calls the httpd method (-e httpd).

By default it listens on port 80, which is a little non-standard and strikes me as strange - were they seriously expecting this to be run in production?! But I began to appreciate this choice when I realised I could omit :8000 in the URL.

node.js

You have to install a package for this - there are a couple to choose from, like node-static, connect, etc. I chose http-server:

$ npm install -g http-server
$ http-server
 

Python

And my favourite of the lot:

$ python -m SimpleHTTPServer
blog comments powered by Disqus