Tuesday, February 18, 2014

Swank - A Stupid-simple static webserver

Today doing some web development I got tired of messing with httpd.conf files with XAMPP every time I changed projects, so I whipped up a little project called swank. Simply run swank from a terminal, optionally giving it the root path (if not the current working directory) and the port (if not 8000). It will spin up a static file webserver on your local machine, and spit back a link you can try in your browser. Ctrl-C to kill when you are done.

Sure, most browsers will open raw local files, but you run into issues with cross-site requests and over permissions. And the closer you can imitate a real webserver in development, the better.To install:
[sudo] npm install -g swank
It is my first item on npm. I was quite impressed with how easy it was to create a module and publish it. It is really nothing more than npm init (which is required for things like Heroku and good practice anyway) and npm publish.

I'd like to eventually drop the Connect middleware requirement, but it works for now (and it is realistically about 15 lines of code). Here is the project on npm. Let me know what you think!

EDIT: The latest version of swank now has optional ngrok support. Just add the --ngrok flag to the command, and have your server tunneled to the outside world. Pretty cool!

No comments:

Post a Comment