Serve.py: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
No edit summary
Line 1: Line 1:
== Simple ==
<source lang="python">
python -m SimpleHTTPServer
</source>
In a time when the terms of "sharing" become increasingly contested and dictated by platforms vying for our personal data and attention, this simple one-liner, which shares the current directory (and potentially sub-directories) on one's local network takes on a political dimension. I share therefore I am!
== Server with CGI support ==
Script to make a local webserver with [[CGI]].
Script to make a local webserver with [[CGI]].



Revision as of 12:02, 2 December 2013

Simple

python -m SimpleHTTPServer

In a time when the terms of "sharing" become increasingly contested and dictated by platforms vying for our personal data and attention, this simple one-liner, which shares the current directory (and potentially sub-directories) on one's local network takes on a political dimension. I share therefore I am!

Server with CGI support

Script to make a local webserver with CGI.

#!/usr/bin/env python
 
import BaseHTTPServer, CGIHTTPServer, sys, argparse
import cgitb; cgitb.enable()  ## This line enables CGI error reporting

parser = argparse.ArgumentParser(description='Happy to serve you')
parser.add_argument('--port', type=int, default=8000, help='the port number to listen to')
args = parser.parse_args()
server = BaseHTTPServer.HTTPServer
handler = CGIHTTPServer.CGIHTTPRequestHandler
server_address = ("", args.port)
handler.cgi_directories = ["/cgi-bin"]
print "Listening on http://localhost:{}".format(args.port)
httpd = server(server_address, handler)
httpd.serve_forever()