Skip to content

Instantly share code, notes, and snippets.

@jtangelder
Created December 24, 2014 11:50
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jtangelder/e445e9a7f5e31c220be6 to your computer and use it in GitHub Desktop.
Save jtangelder/e445e9a7f5e31c220be6 to your computer and use it in GitHub Desktop.
Python SimpleHTTPServer with HTML5 pushState support
#!/usr/bin/env python
# execute in the folder you want the server to run
# starts at port 80
import os
import urlparse
import SimpleHTTPServer
import SocketServer
HOST = ('0.0.0.0', 80)
class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
urlparts = urlparse.urlparse(self.path)
request_file_path = urlparts.path.strip("/")
print request_file_path
if not os.path.exists(request_file_path):
self.path = 'index.html'
return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
httpd = SocketServer.TCPServer(HOST, Handler)
httpd.serve_forever()
@aglassman
Copy link

Thanks, this rocks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment