Update server.py

This commit is contained in:
Nova Cat 2025-01-12 22:00:24 -08:00
parent 6d8dfc7d18
commit 1b996e2599

View file

@ -1,24 +1,43 @@
#!/usr/bin/python3
import asyncio, traceback
from flask import Flask, request, render_template, redirect
from flask import Flask, request, redirect
from hypercorn.config import Config
from hypercorn.asyncio import serve
app = Flask(__name__)
@app.route("/")
def root():
return render_template("home.html")
return """
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://swee.codes/style.css">
<title>Gem2Browser</title>
</head>
<body>
<center>
<h1>Gem2Browser</h1>
<form action="/gem">
<p style="font-size: 15pt;">gemini://<input class="input" value="geminiprotocol.net" type="text" name="gemini"></p><br>
<input type="submit" value="Go!">
</form>
</center>
</body>
</html>
"""
@app.route("/gem")
def relay():
url = request.args.get('gemini')
if url == None:
return redirect("/")
parsed = "<h1>Something went wrong...</h1>\n"
code = "<h1>Something went wrong...</h1>\n"
title = "Something went wrong..."
try:
raise Exception("Not implemented")
except:
parsed += traceback.format_exc()
return render_template("gem.html", code=parsed, title=title)
code += traceback.format_exc()
return f'<!DOCTYPE html>\n<html><head><meta charset="UTF-8"><link rel="stylesheet" href="https://swee.codes/style.css"><title>{title}</title></head><body>{code}</body></html>
'
# Run the Hypercorn ASGI server
conf = Config()