"Refactor app logic in backend/app/app.py and update package dependencies"
This commit is contained in:
parent
5c930ebbfe
commit
aaae49a98d
@ -1324,41 +1324,37 @@ def init_app():
|
||||
|
||||
# App starten
|
||||
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()
|
||||
ssl_context = get_ssl_context()
|
||||
|
||||
# Starte den Haupt-Server mit SSL auf Port 443
|
||||
if ssl_context:
|
||||
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)
|
||||
# Port aus Kommandozeilenargument verwenden, falls angegeben
|
||||
port = args.port if args.port else FLASK_PORT
|
||||
|
||||
# Starte einen zweiten Server auf Port 80 als Fallback
|
||||
# Dies wird in einem separaten Thread ausgeführt
|
||||
def run_fallback_server():
|
||||
# Server starten
|
||||
app_logger.info(f"Server wird auf Port {port} gestartet...")
|
||||
|
||||
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:
|
||||
from werkzeug.serving import make_server
|
||||
fallback_app = Flask("fallback_app")
|
||||
|
||||
@fallback_app.route('/', defaults={'path': ''})
|
||||
@fallback_app.route('/<path:path>')
|
||||
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()
|
||||
app.run(host=FLASK_HOST, port=FLASK_FALLBACK_PORT, debug=FLASK_DEBUG)
|
||||
except Exception as e2:
|
||||
app_logger.error(f"Auch Fallback-Port fehlgeschlagen: {str(e2)}")
|
||||
app_logger.info("Versuche auf Standard-Port 5000 zu starten...")
|
||||
app.run(host=FLASK_HOST, port=5000, debug=FLASK_DEBUG)
|
||||
|
||||
# Content Security Policy anpassen
|
||||
@app.after_request
|
||||
|
@ -6,7 +6,8 @@
|
||||
"scripts": {
|
||||
"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",
|
||||
"start": "python3.11 app.py"
|
||||
"build": "npm install && npm run build:css",
|
||||
"start": "python app.py --port=5000"
|
||||
},
|
||||
"keywords": [
|
||||
"flask",
|
||||
|
Loading…
x
Reference in New Issue
Block a user