"Refactor app logic in backend/app/app.py and update package dependencies"
This commit is contained in:
@@ -1324,41 +1324,37 @@ def init_app():
|
|||||||
|
|
||||||
# App starten
|
# App starten
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
# Kommandozeilenargumente parsen
|
||||||
|
parser = argparse.ArgumentParser(description='MYP Platform - 3D-Drucker Reservierungssystem')
|
||||||
|
parser.add_argument('--port', type=int, help='Port für den Server (überschreibt die Konfiguration)')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
# Initialisierung
|
||||||
init_app()
|
init_app()
|
||||||
ssl_context = get_ssl_context()
|
|
||||||
|
|
||||||
# Starte den Haupt-Server mit SSL auf Port 443
|
# Port aus Kommandozeilenargument verwenden, falls angegeben
|
||||||
if ssl_context:
|
port = args.port if args.port else FLASK_PORT
|
||||||
print(f"Starte Flask-Server mit SSL auf {FLASK_HOST}:{FLASK_PORT}")
|
|
||||||
app.run(host=FLASK_HOST, port=FLASK_PORT, debug=FLASK_DEBUG, ssl_context=ssl_context)
|
|
||||||
else:
|
|
||||||
print(f"Starte Flask-Server ohne SSL auf {FLASK_HOST}:{FLASK_PORT}")
|
|
||||||
app.run(host=FLASK_HOST, port=FLASK_PORT, debug=FLASK_DEBUG)
|
|
||||||
|
|
||||||
# Starte einen zweiten Server auf Port 80 als Fallback
|
# Server starten
|
||||||
# Dies wird in einem separaten Thread ausgeführt
|
app_logger.info(f"Server wird auf Port {port} gestartet...")
|
||||||
def run_fallback_server():
|
|
||||||
|
try:
|
||||||
|
ssl_context = get_ssl_context()
|
||||||
|
if ssl_context:
|
||||||
|
app.run(host=FLASK_HOST, port=port, debug=FLASK_DEBUG, ssl_context=ssl_context)
|
||||||
|
else:
|
||||||
|
app.run(host=FLASK_HOST, port=port, debug=FLASK_DEBUG)
|
||||||
|
except Exception as e:
|
||||||
|
app_logger.error(f"Fehler beim Starten des Servers: {str(e)}")
|
||||||
|
app_logger.info(f"Versuche auf Fallback-Port {FLASK_FALLBACK_PORT} zu starten...")
|
||||||
try:
|
try:
|
||||||
from werkzeug.serving import make_server
|
app.run(host=FLASK_HOST, port=FLASK_FALLBACK_PORT, debug=FLASK_DEBUG)
|
||||||
fallback_app = Flask("fallback_app")
|
except Exception as e2:
|
||||||
|
app_logger.error(f"Auch Fallback-Port fehlgeschlagen: {str(e2)}")
|
||||||
@fallback_app.route('/', defaults={'path': ''})
|
app_logger.info("Versuche auf Standard-Port 5000 zu starten...")
|
||||||
@fallback_app.route('/<path:path>')
|
app.run(host=FLASK_HOST, port=5000, debug=FLASK_DEBUG)
|
||||||
def catch_all(path):
|
|
||||||
# Leite alle Anfragen an HTTPS weiter
|
|
||||||
host = request.host.split(':')[0]
|
|
||||||
return redirect(f"https://{host}:{FLASK_PORT}/{path}")
|
|
||||||
|
|
||||||
server = make_server(FLASK_HOST, FLASK_FALLBACK_PORT, fallback_app)
|
|
||||||
print(f"Starte Fallback-Server auf {FLASK_HOST}:{FLASK_FALLBACK_PORT}")
|
|
||||||
server.serve_forever()
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Fehler beim Starten des Fallback-Servers: {str(e)}")
|
|
||||||
|
|
||||||
# Starte den Fallback-Server in einem separaten Thread
|
|
||||||
fallback_thread = threading.Thread(target=run_fallback_server)
|
|
||||||
fallback_thread.daemon = True
|
|
||||||
fallback_thread.start()
|
|
||||||
|
|
||||||
# Content Security Policy anpassen
|
# Content Security Policy anpassen
|
||||||
@app.after_request
|
@app.after_request
|
||||||
|
@@ -6,7 +6,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build:css": "npx tailwindcss -i ./static/css/input.css -o ./static/css/tailwind.min.css --minify",
|
"build:css": "npx tailwindcss -i ./static/css/input.css -o ./static/css/tailwind.min.css --minify",
|
||||||
"watch:css": "npx tailwindcss -i ./static/css/input.css -o ./static/css/tailwind.min.css --watch",
|
"watch:css": "npx tailwindcss -i ./static/css/input.css -o ./static/css/tailwind.min.css --watch",
|
||||||
"start": "python3.11 app.py"
|
"build": "npm install && npm run build:css",
|
||||||
|
"start": "python app.py --port=5000"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"flask",
|
"flask",
|
||||||
|
Reference in New Issue
Block a user