added basic website
This commit is contained in:
parent
62511687c7
commit
cfd79674f6
1 changed files with 50 additions and 3 deletions
53
main.py
53
main.py
|
|
@ -1,6 +1,53 @@
|
|||
def main():
|
||||
print("Hello from syncide-test!")
|
||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||
|
||||
class MyServerHandler(BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
if self.path == '/':
|
||||
self.send_response(200)
|
||||
self.send_header("Content-type", "text/html")
|
||||
self.end_headers()
|
||||
|
||||
html = """
|
||||
<html>
|
||||
<head><title>Home</title></head>
|
||||
<body>
|
||||
<h1>Welcome to the Home Page</h1>
|
||||
<p>This is a simple preview.</p>
|
||||
<a href="subpage">Go to Subpage</a>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
self.wfile.write(html.encode("utf-8"))
|
||||
|
||||
elif self.path == '/subpage':
|
||||
self.send_response(200)
|
||||
self.send_header("Content-type", "text/html")
|
||||
self.end_headers()
|
||||
|
||||
html = """
|
||||
<html>
|
||||
<head><title>Subpage</title></head>
|
||||
<body>
|
||||
<h1>This is the Subpage!</h1>
|
||||
<a href=".">Go back to Home</a>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
self.wfile.write(html.encode("utf-8"))
|
||||
|
||||
else:
|
||||
self.send_response(404)
|
||||
self.send_header("Content-type", "text/html")
|
||||
self.end_headers()
|
||||
self.wfile.write(b"<h1>404 Not Found</h1>")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
port = 8080
|
||||
server = HTTPServer(("0.0.0.0", port), MyServerHandler)
|
||||
print(f"Server running at http://0.0.0.0:{port}")
|
||||
|
||||
try:
|
||||
server.serve_forever()
|
||||
except KeyboardInterrupt:
|
||||
print("\nShutting down server.")
|
||||
server.server_close()
|
||||
Loading…
Add table
Add a link
Reference in a new issue