Compare commits
2 commits
main
...
web_previe
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
64297d2e98 | ||
|
|
cfd79674f6 |
1 changed files with 50 additions and 3 deletions
53
main.py
53
main.py
|
|
@ -1,6 +1,53 @@
|
||||||
def main():
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||||
print("Hello from syncide-test!")
|
|
||||||
|
|
||||||
|
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. wow coool</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__":
|
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