We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I'm facing many issue with the types using Deno + jsr:@hono/hono + npm:hono-rate-limiter The main one is the following:
jsr:@hono/hono
npm:hono-rate-limiter
The code is pretty new, without so many personal things yet: It was originally inside the RateLimitMiddleware class
RateLimitMiddleware
import { Context, Hono } from "hono"; import { HTTP_STATUS_CODES } from '@utils/http.constants.ts'; import { AuthMiddleware, ErrorMiddleware, RateLimitMiddleware } from '@src/middlewares/index.ts'; import { rateLimiter } from 'npm:hono-rate-limiter'; const app = new Hono(); // Made following the examples provided const limiter = rateLimiter({ windowMs: Deno.env.has('RATE_LIMIT_WINDOW_MS') ? +Deno.env.get('RATE_LIMIT_WINDOW_MS')! : 60_000, // 1 minute limit: Deno.env.has('RATE_LIMIT_MAX_REQUESTS') ? +Deno.env.get('RATE_LIMIT_MAX_REQUESTS')! : 10, standardHeaders: 'draft-6', keyGenerator: (c) => c.req.header('x-forwarded-for') ?? '', // No types }); // Internal Middlewares app.onError(ErrorMiddleware.handler); app.use(limiter); // ... our routes here export app;
Issue:
The other one is if I also try to type the keyGenerator it breaks too: keyGenerator: (c: Context) => c.req.header('x-forwarded-for') ?? '',
keyGenerator
keyGenerator: (c: Context) => c.req.header('x-forwarded-for') ?? '',
Aaaannnd... By typing the return of rateLimiter, it breaks like this one:
rateLimiter
The text was updated successfully, but these errors were encountered:
I think this sould resolve your issue -
app.use(rateLimiter({ windowMs: Deno.env.has('RATE_LIMIT_WINDOW_MS') ? +Deno.env.get('RATE_LIMIT_WINDOW_MS')! : 60_000, // 1 minute limit: Deno.env.has('RATE_LIMIT_MAX_REQUESTS') ? +Deno.env.get('RATE_LIMIT_MAX_REQUESTS')! : 10, standardHeaders: 'draft-6', keyGenerator: (c) => c.req.header('x-forwarded-for') ?? '', // No types }))
You need to provide the E, P and I, generic types in the limiter.
E
P
I
Sorry, something went wrong.
MathurAditya724
No branches or pull requests
I'm facing many issue with the types using Deno +
jsr:@hono/hono
+npm:hono-rate-limiter
The main one is the following:
The code is pretty new, without so many personal things yet:
It was originally inside the
RateLimitMiddleware
classIssue:
The other one is if I also try to type the
keyGenerator
it breaks too:keyGenerator: (c: Context) => c.req.header('x-forwarded-for') ?? '',
Aaaannnd... By typing the return of
rateLimiter
, it breaks like this one:The text was updated successfully, but these errors were encountered: