31 lines
796 B
Python
31 lines
796 B
Python
import os
|
|
from http.server import HTTPServer, SimpleHTTPRequestHandler
|
|
|
|
# Default error message template
|
|
DEFAULT_ERROR_MESSAGE = """\
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Single Page Apps for GitHub Pages</title>
|
|
<script>
|
|
sessionStorage.redirect = location.href;
|
|
</script>
|
|
<meta http-equiv="refresh" content="0;URL='/'">
|
|
</head>
|
|
<body>
|
|
</body>
|
|
</html>
|
|
"""
|
|
|
|
class MyHandler(SimpleHTTPRequestHandler):
|
|
def send_error(self, code, message=None):
|
|
if code == 404:
|
|
self.error_message_format = DEFAULT_ERROR_MESSAGE
|
|
SimpleHTTPRequestHandler.send_error(self, code, message)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
httpd = HTTPServer(('', 4002), MyHandler)
|
|
print("Serving app on port 4002 ...")
|
|
httpd.serve_forever() |