add server.py

This commit is contained in:
2025-12-09 00:03:09 +01:00
parent 30142a0425
commit 3d95d19da5

26
server.py Normal file
View File

@@ -0,0 +1,26 @@
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()