"feat: Update project structure documentation and add health route"
This commit is contained in:
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 });
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user