cista-storage/cista/server80.py

25 lines
780 B
Python
Raw Permalink Normal View History

from sanic import Sanic, exceptions, response
2023-10-21 17:17:09 +01:00
app = Sanic("server80")
# Send all HTTP users to HTTPS
@app.exception(exceptions.NotFound, exceptions.MethodNotSupported)
def redirect_everything_else(request, exception):
server, path = request.server_name, request.path
if server and path.startswith("/"):
return response.redirect(f"https://{server}{path}", status=308)
return response.text("Bad Request. Please use HTTPS!", status=400)
# ACME challenge for LetsEncrypt
2023-10-19 01:13:47 +01:00
@app.get("/.well-known/acme-challenge/<challenge>")
async def letsencrypt(request, challenge):
try:
return response.text(acme_challenges[challenge])
except KeyError:
return response.text(f"ACME challenge not found: {challenge}", status=404)
acme_challenges = {}