Created
August 26, 2015 16:37
-
-
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.
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
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