Files
Krzak.org/server.py
2025-12-09 00:03:09 +01:00

27 lines
717 B
Python

import os
import sys
from http.server import HTTPServer as S
from http.server import SimpleHTTPRequestHandler as H
class C(H):
def do_GET(self):
p = self.path
if p.endswith("/"):
p += "index.html"
elif "." not in p.split("/")[-1]:
r = os.path.join(os.getcwd(), p.lstrip("/"))
if os.path.exists(r + ".html"):
p += ".html"
elif os.path.isdir(r):
p += "/index.html"
self.path = p
return H.do_GET(self)
if __name__ == "__main__":
d = sys.argv[1] if len(sys.argv) > 1 else "."
p = int(sys.argv[2]) if len(sys.argv) > 2 else 8000
os.chdir(d)
S(("0.0.0.0", p), C).serve_forever()