Compare commits
No commits in common. "web_preview" and "main" have entirely different histories.
web_previe
...
main
1 changed files with 3 additions and 50 deletions
53
main.py
53
main.py
|
|
@ -1,53 +1,6 @@
|
||||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
def main():
|
||||||
|
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__":
|
||||||
port = 8080
|
main()
|
||||||
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