Created
August 6, 2014 22:00
-
-
Save parhammmm/6ee6c23942a7f4e778e8 to your computer and use it in GitHub Desktop.
Revisions
-
parhammmm created this gist
Aug 6, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ #!/usr/bin/env python import os import urlparse import SimpleHTTPServer import SocketServer from mimetypes import guess_type # Directory containing the static files ROOT_DIR = 'debug/' HOST = ('0.0.0.0', 3000) class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler): def do_GET(self): urlparts = urlparse.urlparse(self.path) urlpath = urlparts.path.strip("/") mime_type = 'text/html' response_file_path = '%sindex.html' % ROOT_DIR request_file_path = '%s%s' % (ROOT_DIR, urlpath) if urlpath and os.path.exists(request_file_path): mime_type, encoding = guess_type(self.path) response_file_path = request_file_path self.send_response(200) self.send_header('Content-type', mime_type) self.end_headers() self.wfile.write(open(response_file_path).read()) httpd = SocketServer.TCPServer(HOST, Handler) httpd.serve_forever()