-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
24 lines (21 loc) · 818 Bytes
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from http.server import HTTPServer, BaseHTTPRequestHandler
class ServerHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.path = "index.html"
try:
with open(self.path) as file:
content = file.read()
self.send_response(200)
self.send_header("Content_type", "text/html")
self.end_headers()
self.wfile.write(bytes(content, "utf-8"))
except Exception as error:
print(error)
class ManageServer:
def __str__(self, host="localhost", port='8080'):
self.host = host
self.port = port
def run_server(self):
httpd = HTTPServer((self.host, self.port), ServerHandler)
print(f"Server is running at {self.host}:{self.port}")
httpd.serve_forever()