Skip to content

Instantly share code, notes, and snippets.

@bradmontgomery
Created August 26, 2015 16:37
Show Gist options
  • Save bradmontgomery/fd02e55a3aec448b48ff to your computer and use it in GitHub Desktop.
Save bradmontgomery/fd02e55a3aec448b48ff to your computer and use it in GitHub Desktop.
Subclass of python's built-in SimpleHTTPRequestHandler that only serves a single file.
import http.server
import socketserver
PORT = 5555
class IndexHandler(http.server.SimpleHTTPRequestHandler):
"""Always show the index no matter what the requested path."""
def parse_request(self, *args, **kwargs):
super().parse_request(*args, **kwargs)
self.path = "index.html"
return True
httpd = socketserver.TCPServer(("", PORT), IndexHandler)
print("serving at port", PORT)
httpd.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment