"feat: Update project structure documentation and add health route"
This commit is contained in:
parent
359cb4a219
commit
57d4d9c4e4
@ -1,5 +1,6 @@
|
|||||||
from flask import Flask, request, jsonify, g, redirect, url_for, session as flask_session, render_template, flash, send_from_directory
|
from flask import Flask, request, jsonify, g, redirect, url_for, session as flask_session, render_template, flash, send_from_directory
|
||||||
from werkzeug.security import generate_password_hash, check_password_hash
|
from werkzeug.security import generate_password_hash, check_password_hash
|
||||||
|
from flask_cors import CORS
|
||||||
import secrets # Für bessere Salt-Generierung
|
import secrets # Für bessere Salt-Generierung
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
import jwt
|
import jwt
|
||||||
@ -40,6 +41,14 @@ def create_app(config_name=None):
|
|||||||
"""
|
"""
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
# CORS-Konfiguration für Frontend-Server
|
||||||
|
cors_origins = os.environ.get('CORS_ORIGINS', 'http://localhost:3000').split(',')
|
||||||
|
CORS(app,
|
||||||
|
origins=cors_origins,
|
||||||
|
supports_credentials=True,
|
||||||
|
allow_headers=['Content-Type', 'Authorization', 'X-Requested-With'],
|
||||||
|
methods=['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'])
|
||||||
|
|
||||||
# Bestimme Konfiguration
|
# Bestimme Konfiguration
|
||||||
if config_name is None:
|
if config_name is None:
|
||||||
config_name = os.environ.get('FLASK_ENV', 'development')
|
config_name = os.environ.get('FLASK_ENV', 'development')
|
||||||
@ -86,6 +95,14 @@ def create_app(config_name=None):
|
|||||||
# Initialisierung - wird später durch create_app ersetzt
|
# Initialisierung - wird später durch create_app ersetzt
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
# CORS-Konfiguration für Frontend-Server (Legacy)
|
||||||
|
cors_origins = os.environ.get('CORS_ORIGINS', 'http://localhost:3000').split(',')
|
||||||
|
CORS(app,
|
||||||
|
origins=cors_origins,
|
||||||
|
supports_credentials=True,
|
||||||
|
allow_headers=['Content-Type', 'Authorization', 'X-Requested-With'],
|
||||||
|
methods=['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'])
|
||||||
|
|
||||||
# Initialisiere Netzwerkkonfiguration
|
# Initialisiere Netzwerkkonfiguration
|
||||||
network_config = NetworkConfig(app)
|
network_config = NetworkConfig(app)
|
||||||
|
|
||||||
@ -1705,7 +1722,30 @@ def job_status(job_id):
|
|||||||
|
|
||||||
@app.route('/api/test', methods=['GET'])
|
@app.route('/api/test', methods=['GET'])
|
||||||
def test():
|
def test():
|
||||||
return jsonify({'message': 'MYP Backend API funktioniert!'})
|
return jsonify({'message': 'API funktioniert!', 'status': 'success'})
|
||||||
|
|
||||||
|
@app.route('/health', methods=['GET'])
|
||||||
|
def health_check():
|
||||||
|
"""Health Check Endpoint für Backend-Server"""
|
||||||
|
try:
|
||||||
|
# Prüfe Datenbankverbindung
|
||||||
|
db = get_db()
|
||||||
|
db.execute('SELECT 1').fetchone()
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'status': 'healthy',
|
||||||
|
'service': 'myp-backend',
|
||||||
|
'timestamp': datetime.datetime.utcnow().isoformat() + 'Z',
|
||||||
|
'version': '1.0.0',
|
||||||
|
'database': 'connected'
|
||||||
|
}), 200
|
||||||
|
except Exception as e:
|
||||||
|
return jsonify({
|
||||||
|
'status': 'unhealthy',
|
||||||
|
'service': 'myp-backend',
|
||||||
|
'timestamp': datetime.datetime.utcnow().isoformat() + 'Z',
|
||||||
|
'error': str(e)
|
||||||
|
}), 503
|
||||||
|
|
||||||
@app.route('/api/create-initial-admin', methods=['POST'])
|
@app.route('/api/create-initial-admin', methods=['POST'])
|
||||||
def create_initial_admin():
|
def create_initial_admin():
|
||||||
|
49
frontend/src/app/health/route.ts
Normal file
49
frontend/src/app/health/route.ts
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import { NextRequest, NextResponse } from 'next/server';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Health Check Endpoint für Frontend-Server
|
||||||
|
* GET /health
|
||||||
|
*/
|
||||||
|
export async function GET(request: NextRequest) {
|
||||||
|
try {
|
||||||
|
// Prüfe Backend-Verbindung
|
||||||
|
const backendUrl = process.env.BACKEND_API_URL || 'http://localhost:5000';
|
||||||
|
let backendStatus = 'unknown';
|
||||||
|
|
||||||
|
try {
|
||||||
|
// AbortController für Timeout verwenden
|
||||||
|
const controller = new AbortController();
|
||||||
|
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
||||||
|
|
||||||
|
const backendResponse = await fetch(`${backendUrl}/health`, {
|
||||||
|
method: 'GET',
|
||||||
|
signal: controller.signal,
|
||||||
|
});
|
||||||
|
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
backendStatus = backendResponse.ok ? 'connected' : 'error';
|
||||||
|
} catch {
|
||||||
|
backendStatus = 'disconnected';
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 'healthy',
|
||||||
|
service: 'myp-frontend',
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
version: '1.0.0',
|
||||||
|
backend: {
|
||||||
|
url: backendUrl,
|
||||||
|
status: backendStatus
|
||||||
|
},
|
||||||
|
environment: process.env.NODE_ENV || 'development'
|
||||||
|
}, { status: 200 });
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 'unhealthy',
|
||||||
|
service: 'myp-frontend',
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
error: error instanceof Error ? error.message : 'Unknown error'
|
||||||
|
}, { status: 503 });
|
||||||
|
}
|
||||||
|
}
|
100
start.ps1
100
start.ps1
@ -1,100 +0,0 @@
|
|||||||
# 🚀 MYP - Manage your Printer (Hauptstartskript)
|
|
||||||
# Weiterleitung an das optimierte Infrastructure-Startskript
|
|
||||||
|
|
||||||
param(
|
|
||||||
[Parameter(Position=0)]
|
|
||||||
[ValidateSet("dev", "prod", "test", "development", "production")]
|
|
||||||
[string]$Environment = "dev",
|
|
||||||
|
|
||||||
[switch]$Help,
|
|
||||||
[switch]$Version,
|
|
||||||
[switch]$Clean
|
|
||||||
)
|
|
||||||
|
|
||||||
# Farbdefinitionen für bessere Ausgabe
|
|
||||||
$Colors = @{
|
|
||||||
Info = "Cyan"
|
|
||||||
Success = "Green"
|
|
||||||
Warning = "Yellow"
|
|
||||||
Error = "Red"
|
|
||||||
Header = "Magenta"
|
|
||||||
}
|
|
||||||
|
|
||||||
function Write-ColorOutput {
|
|
||||||
param([string]$Message, [string]$Color = "White")
|
|
||||||
Write-Host $Message -ForegroundColor $Colors[$Color]
|
|
||||||
}
|
|
||||||
|
|
||||||
# Header anzeigen
|
|
||||||
Write-ColorOutput "MYP - Manage your Printer" "Header"
|
|
||||||
Write-ColorOutput "=======================================" "Header"
|
|
||||||
|
|
||||||
# Hilfe anzeigen
|
|
||||||
if ($Help) {
|
|
||||||
Write-ColorOutput "`nVerwendung:" "Info"
|
|
||||||
Write-ColorOutput " .\start.ps1 [Environment] [Optionen]" "White"
|
|
||||||
Write-ColorOutput "`nVerfügbare Umgebungen:" "Info"
|
|
||||||
Write-ColorOutput " dev, development - Entwicklungsumgebung (Standard)" "White"
|
|
||||||
Write-ColorOutput " prod, production - Produktionsumgebung" "White"
|
|
||||||
Write-ColorOutput " test - Testumgebung" "White"
|
|
||||||
Write-ColorOutput "`nOptionen:" "Info"
|
|
||||||
Write-ColorOutput " -Help - Diese Hilfe anzeigen" "White"
|
|
||||||
Write-ColorOutput " -Version - Versionsinformationen anzeigen" "White"
|
|
||||||
Write-ColorOutput " -Clean - System vor Start bereinigen" "White"
|
|
||||||
Write-ColorOutput "`nBeispiele:" "Info"
|
|
||||||
Write-ColorOutput " .\start.ps1 # Entwicklungsumgebung starten" "White"
|
|
||||||
Write-ColorOutput " .\start.ps1 prod # Produktionsumgebung starten" "White"
|
|
||||||
Write-ColorOutput " .\start.ps1 dev -Clean # Mit Bereinigung starten" "White"
|
|
||||||
exit 0
|
|
||||||
}
|
|
||||||
|
|
||||||
# Version anzeigen
|
|
||||||
if ($Version) {
|
|
||||||
Write-ColorOutput "`nSysteminformationen:" "Info"
|
|
||||||
Write-ColorOutput " MYP Version: 2.0.0" "White"
|
|
||||||
Write-ColorOutput " PowerShell: $($PSVersionTable.PSVersion)" "White"
|
|
||||||
Write-ColorOutput " OS: $($PSVersionTable.OS)" "White"
|
|
||||||
Write-ColorOutput " Architektur: $env:PROCESSOR_ARCHITECTURE" "White"
|
|
||||||
exit 0
|
|
||||||
}
|
|
||||||
|
|
||||||
# Bereinigung falls gewünscht
|
|
||||||
if ($Clean) {
|
|
||||||
Write-ColorOutput "`nSystem wird bereinigt..." "Warning"
|
|
||||||
& ".\infrastructure\scripts\cleanup.ps1" -Force
|
|
||||||
if ($LASTEXITCODE -ne 0) {
|
|
||||||
Write-ColorOutput "Bereinigung fehlgeschlagen!" "Error"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
Write-ColorOutput "System erfolgreich bereinigt!" "Success"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Prüfe ob Infrastructure-Skript existiert
|
|
||||||
$InfraScript = ".\infrastructure\scripts\start.ps1"
|
|
||||||
if (-not (Test-Path $InfraScript)) {
|
|
||||||
Write-ColorOutput "`nInfrastructure-Startskript nicht gefunden: $InfraScript" "Error"
|
|
||||||
Write-ColorOutput " Bitte stellen Sie sicher, dass die Projektstruktur vollständig ist." "Error"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Weiterleitung an Infrastructure-Skript
|
|
||||||
Write-ColorOutput "`nWeiterleitung an Infrastructure-Startskript..." "Info"
|
|
||||||
Write-ColorOutput " Umgebung: $Environment" "White"
|
|
||||||
|
|
||||||
try {
|
|
||||||
& $InfraScript $Environment
|
|
||||||
$ExitCode = $LASTEXITCODE
|
|
||||||
|
|
||||||
if ($ExitCode -eq 0) {
|
|
||||||
Write-ColorOutput "`nMYP erfolgreich gestartet!" "Success"
|
|
||||||
Write-ColorOutput " Zugriff über: http://localhost" "Info"
|
|
||||||
} else {
|
|
||||||
Write-ColorOutput "`nStart fehlgeschlagen (Exit Code: $ExitCode)" "Error"
|
|
||||||
}
|
|
||||||
|
|
||||||
exit $ExitCode
|
|
||||||
} catch {
|
|
||||||
Write-ColorOutput "`nUnerwarteter Fehler beim Start:" "Error"
|
|
||||||
Write-ColorOutput " $($_.Exception.Message)" "Error"
|
|
||||||
exit 1
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user