add server.py
This commit is contained in:
26
server.py
Normal file
26
server.py
Normal 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()
|
||||||
Reference in New Issue
Block a user