@@ -15,10 +15,8 @@ const nextConfig = {
|
|||||||
];
|
];
|
||||||
},
|
},
|
||||||
|
|
||||||
// Configuración experimental para mejorar el manejo de headers
|
// Configuración de paquetes externos para server components
|
||||||
experimental: {
|
serverExternalPackages: ['ping'],
|
||||||
serverComponentsExternalPackages: ['ping'],
|
|
||||||
},
|
|
||||||
|
|
||||||
// Configuración de red
|
// Configuración de red
|
||||||
env: {
|
env: {
|
||||||
|
|||||||
@@ -136,13 +136,13 @@ export async function POST(request) {
|
|||||||
statistics: stats,
|
statistics: stats,
|
||||||
rateLimit: {
|
rateLimit: {
|
||||||
limit: rateLimitResult.limit,
|
limit: rateLimitResult.limit,
|
||||||
remaining: rateLimitResult.remaining - 1,
|
remaining: rateLimitResult.remaining,
|
||||||
resetTime: rateLimitResult.resetTime
|
resetTime: rateLimitResult.resetTime
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
headers: {
|
headers: {
|
||||||
'X-RateLimit-Limit': rateLimitResult.limit.toString(),
|
'X-RateLimit-Limit': rateLimitResult.limit.toString(),
|
||||||
'X-RateLimit-Remaining': (rateLimitResult.remaining - 1).toString(),
|
'X-RateLimit-Remaining': rateLimitResult.remaining.toString(),
|
||||||
'X-RateLimit-Reset': rateLimitResult.resetTime.toString()
|
'X-RateLimit-Reset': rateLimitResult.resetTime.toString()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export default function RateLimitInfo({ rateLimitInfo }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getStatusColor = () => {
|
const getStatusColor = () => {
|
||||||
const percentage = (remaining / limit) * 100;
|
const percentage = Math.max(0, (remaining / limit) * 100);
|
||||||
|
|
||||||
if (percentage > 50) {
|
if (percentage > 50) {
|
||||||
return 'bg-green-500';
|
return 'bg-green-500';
|
||||||
@@ -35,7 +35,7 @@ export default function RateLimitInfo({ rateLimitInfo }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getTextColor = () => {
|
const getTextColor = () => {
|
||||||
const percentage = (remaining / limit) * 100;
|
const percentage = Math.max(0, (remaining / limit) * 100);
|
||||||
|
|
||||||
if (percentage > 50) {
|
if (percentage > 50) {
|
||||||
return 'text-green-700 dark:text-green-300';
|
return 'text-green-700 dark:text-green-300';
|
||||||
@@ -47,7 +47,7 @@ export default function RateLimitInfo({ rateLimitInfo }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getBorderColor = () => {
|
const getBorderColor = () => {
|
||||||
const percentage = (remaining / limit) * 100;
|
const percentage = Math.max(0, (remaining / limit) * 100);
|
||||||
|
|
||||||
if (percentage > 50) {
|
if (percentage > 50) {
|
||||||
return 'border-green-200 dark:border-green-800';
|
return 'border-green-200 dark:border-green-800';
|
||||||
@@ -59,7 +59,7 @@ export default function RateLimitInfo({ rateLimitInfo }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getBgColor = () => {
|
const getBgColor = () => {
|
||||||
const percentage = (remaining / limit) * 100;
|
const percentage = Math.max(0, (remaining / limit) * 100);
|
||||||
|
|
||||||
if (percentage > 50) {
|
if (percentage > 50) {
|
||||||
return 'bg-green-50 dark:bg-green-900/20';
|
return 'bg-green-50 dark:bg-green-900/20';
|
||||||
@@ -85,20 +85,20 @@ export default function RateLimitInfo({ rateLimitInfo }) {
|
|||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
<div className="flex justify-between text-xs text-gray-600 dark:text-gray-400 mb-1">
|
<div className="flex justify-between text-xs text-gray-600 dark:text-gray-400 mb-1">
|
||||||
<span>Requests remaining</span>
|
<span>Requests remaining</span>
|
||||||
<span>{remaining} / {limit}</span>
|
<span>{Math.max(0, remaining)} / {limit}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2">
|
<div className="w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2">
|
||||||
<div
|
<div
|
||||||
className={`h-2 rounded-full transition-all duration-300 ${getStatusColor()}`}
|
className={`h-2 rounded-full transition-all duration-300 ${getStatusColor()}`}
|
||||||
style={{ width: `${(remaining / limit) * 100}%` }}
|
style={{ width: `${Math.max(0, Math.min(100, (remaining / limit) * 100))}%` }}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="text-right">
|
<div className="text-right">
|
||||||
<div className={`text-lg font-bold ${getTextColor()}`}>
|
<div className={`text-lg font-bold ${getTextColor()}`}>
|
||||||
{remaining}
|
{Math.max(0, remaining)}
|
||||||
</div>
|
</div>
|
||||||
<div className="text-xs text-gray-500 dark:text-gray-400">
|
<div className="text-xs text-gray-500 dark:text-gray-400">
|
||||||
left
|
left
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ export class RateLimiter {
|
|||||||
return {
|
return {
|
||||||
allowed,
|
allowed,
|
||||||
limit: this.limit,
|
limit: this.limit,
|
||||||
remaining: Math.max(0, this.limit - requestCount - (allowed ? 1 : 0)),
|
remaining: Math.max(0, this.limit - (requestCount + (allowed ? 1 : 0))),
|
||||||
resetTime: data.resetTime,
|
resetTime: data.resetTime,
|
||||||
requestCount: requestCount + (allowed ? 1 : 0)
|
requestCount: requestCount + (allowed ? 1 : 0)
|
||||||
};
|
};
|
||||||
|
|||||||
Referencia en una nueva incidencia
Block a user