DWDeathermap/main.py
2022-12-29 09:02:15 +01:00

21 lines
684 B
Python

from flask import Flask
import SETTINGS
import routes
import re
app = Flask(SETTINGS.FLASK_NAME)
@app.route('/', defaults={'route': '/'}) # catch HTTP / and set route to ""
@app.route("/<path:route>") # catch everything else and set route to the path
def route(route: str):
if not route.endswith("/"):
route += "/"
for r in routes.ROUTES:
if match := re.match(r, route):
return routes.ROUTES[r](match) # call the handler for the function
return "<html><head></head><body><h1>404 Not found!</h1></body></html>", 404 # if nothing matches return 404 Not Found
if __name__ == "__main__":
app.run(SETTINGS.HTTP_HOST, SETTINGS.HTTP_PORT)