node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org ยป



Static File Serving and Reverse Proxying, for fun and deception


Sleight allows you to easily set up a local server that serves static files when you have those files present, and reverse proxies to a remote server when those files aren't present.

In effect, for front-end developers, static pages on a Sleight server simulate the behaviour of pages served from the file protocol, in that their XHRs can violate cross-domain policy (because the cross-domain requests go through the server from the same origin). If that makes sense.

It's mostly useful for PhoneGap development, when you may want to test your app from a web server though it will ultimately run from the file protocol.


$ npm install sleight


$ cd my_static_site
$ ls
index.html another.html image.png
$ cat index.html
<p>Hello World!</p>
$ curl
<p>Goodbye Cruel World</p>
$ sleight port=4000

(in another shell)

$ curl http://localhost:4000/
<p>Hello World!</p>
$ curl http://localhost:4000/goodbye
<p>Goodbye Cruel World</p>

Sleight can also be required as a common js module

sleight = require('sleight'){
    port: 4000
	, public: "~/my_static_site"
	, target: ""

Sleight is specced with vows

$ git clone alunny/sleight # use hub!
$ cd sleight
$ vows spec/sleight_spec.js