Now server accepts binding port or addr:port

* Set it like this:
  python3 server.py 8081
  or
  python3 server.py 127.0.0.1:8081
This commit is contained in:
Bofh 2021-02-10 19:16:49 +01:00
parent 29dea31a0b
commit 9aaa5f4b34
1 changed files with 22 additions and 4 deletions

View File

@ -24,7 +24,20 @@ class MyServer(BaseHTTPRequestHandler):
# lists accounts on a pretty HTML + CSS
# making sure there is no XSS possible on account names
elif parts[0] == 'mirrors':
self.wfile.write(bytes('HTML', "utf-8"))
html = """<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Pixelfed IG Mirrors</title>
</head>
<body>
<style type="text/css">
</style>
<div id="mirrors">{mirrors}</div>
</body>
</html>
"""
self.wfile.write(bytes(html, "utf-8"))
return
@ -74,10 +87,15 @@ class MyServer(BaseHTTPRequestHandler):
if __name__ == "__main__":
addr = '0.0.0.0'
port = 8080
if len(sys.argv) > 1:
addr = sys.argv[1]
if len(sys.argv) > 2:
port = sys.argv[2]
arg = sys.argv[1].strip()
if ':' in arg:
ps = arg.split(':')
addr = ps[0]
port = int(ps[1])
else:
port = int(arg)
webServer = HTTPServer((addr, port), MyServer)
print("Server started http://%s:%s" % (addr, port))