❌ [ERROR] Error in ProxyController: Error inside ProxyWorker
✘ [ERROR] Error in ProxyController: Error inside ProxyWorker
{
name: 'Error',
message: 'Network connection lost.',
stack: 'Error: Network connection lost.'
}
✘ [ERROR] Error in ProxyController: Error inside ProxyWorker
{
name: 'Error',
message: 'Network connection lost.',
stack: 'Error: Network connection lost.'
}
export const CheckLimitExceed = async (c: RequestT, next: Next) => {
try {
const { KV, ENVIRONMENT } = env<ENV>(c, 'workerd');
const ip =
ENVIRONMENT === 'development'
? '127.0.0.1'
: c.req.header('x-real-ip') || c.req.header('cf-connecting-ip');
const key = generateKvKey(ip);
if (!key) {
return c.json(
{
success: false,
err: true,
message: 'Bad Request',
},
400
);
}
const value = await KV.get(key);
if (!value) {
await KV.put(key, '1', { expirationTtl: expire_time });
await next();
return;
}
if (Number(value) >= PER_DAY_SHARING_LIMIT) {
return c.json(
{
success: false,
err: true,
message: `Limit exceeded for today. Please try again later.`,
},
403
);
}
await next();
} catch (err) {
return c.json(
{
success: false,
err: true,
message: 'Internal Server Error',
},
500
);
}
};
export const CheckLimitExceed = async (c: RequestT, next: Next) => {
try {
const { KV, ENVIRONMENT } = env<ENV>(c, 'workerd');
const ip =
ENVIRONMENT === 'development'
? '127.0.0.1'
: c.req.header('x-real-ip') || c.req.header('cf-connecting-ip');
const key = generateKvKey(ip);
if (!key) {
return c.json(
{
success: false,
err: true,
message: 'Bad Request',
},
400
);
}
const value = await KV.get(key);
if (!value) {
await KV.put(key, '1', { expirationTtl: expire_time });
await next();
return;
}
if (Number(value) >= PER_DAY_SHARING_LIMIT) {
return c.json(
{
success: false,
err: true,
message: `Limit exceeded for today. Please try again later.`,
},
403
);
}
await next();
} catch (err) {
return c.json(
{
success: false,
err: true,
message: 'Internal Server Error',
},
500
);
}
};
router.get('/example/:id', CheckLimitExceed, getData);
router.get('/example/:id', CheckLimitExceed, getData);
1 Reply
Anyone?