Created
December 24, 2014 11:50
-
-
Save jtangelder/e445e9a7f5e31c220be6 to your computer and use it in GitHub Desktop.
Python SimpleHTTPServer with HTML5 pushState support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, this rocks!