File Server
Friday, May 1, 2015
Python has a neat feature that lets you serve files from the current directory.
# Python 2
$ python2 -m SimpleHTTPServer
# Python 3
$ python3 -m http.server
I always thought this was a quick and useful way to share files on a local network. Given that Factor has a HTTP Server, we should be able to implement this!
We already have support for serving static content and serving CGI scripts, so we can very simply implement a script to create and launch a HTTP server for the current directory (or the one specified on the command-line), logging HTTP connections to stdout.
This is available in the file-server vocabulary, now you can:
$ factor -run=file-server [--cgi] [path]
Currently, this defaults to serving files on port 8080 from all available network interfaces. In the future, it would be nice to add the ability to specify port and network interfaces to bind.