69
src/app/api/status/route.js
Archivo normal
69
src/app/api/status/route.js
Archivo normal
@@ -0,0 +1,69 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { RateLimiter } from '../../../lib/rate-limiter';
|
||||
|
||||
// Crear instancia del rate limiter
|
||||
const rateLimiter = new RateLimiter();
|
||||
|
||||
export async function GET(request) {
|
||||
try {
|
||||
// Obtener IP del cliente
|
||||
const forwarded = request.headers.get('x-forwarded-for');
|
||||
const clientIP = forwarded
|
||||
? forwarded.split(',')[0].trim()
|
||||
: request.headers.get('x-real-ip') || 'unknown';
|
||||
|
||||
// Obtener estadísticas del rate limiter para este cliente
|
||||
const rateLimitStats = rateLimiter.getStats(clientIP);
|
||||
|
||||
return NextResponse.json({
|
||||
service: 'API Ping Service',
|
||||
version: '1.0.0',
|
||||
status: 'operational',
|
||||
timestamp: new Date().toISOString(),
|
||||
uptime: process.uptime(),
|
||||
clientInfo: {
|
||||
ip: clientIP,
|
||||
rateLimit: rateLimitStats
|
||||
},
|
||||
features: {
|
||||
maxPingsPerRequest: 10,
|
||||
maxTimeout: 10000,
|
||||
minTimeout: 1000,
|
||||
supportedProtocols: ['ICMP'],
|
||||
restrictions: [
|
||||
'No private IP addresses',
|
||||
'No localhost addresses',
|
||||
'No reserved IP ranges',
|
||||
'Rate limited to 10 requests per minute'
|
||||
]
|
||||
},
|
||||
endpoints: {
|
||||
ping: {
|
||||
path: '/api/ping',
|
||||
method: 'POST',
|
||||
description: 'Perform ping test to specified target',
|
||||
parameters: {
|
||||
target: 'IP address or hostname (required)',
|
||||
count: 'Number of pings (1-10, default: 4)',
|
||||
timeout: 'Timeout in milliseconds (1000-10000, default: 5000)'
|
||||
}
|
||||
},
|
||||
status: {
|
||||
path: '/api/status',
|
||||
method: 'GET',
|
||||
description: 'Get service status and client information'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('Status API error:', error);
|
||||
|
||||
return NextResponse.json({
|
||||
service: 'API Ping Service',
|
||||
status: 'error',
|
||||
timestamp: new Date().toISOString(),
|
||||
error: 'Internal server error'
|
||||
}, { status: 500 });
|
||||
}
|
||||
}
|
||||
Referencia en una nueva incidencia
Block a user