-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
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
Type mismatch with Hono req and ip #477
Labels
bug
Something isn't working
Comments
@blaine-arcjet we could fix this specifically, or we could create a new issue to add a proper Hono SDK because I had to manually construct the |
Some preliminary research here:
Full example: import arcjet, { tokenBucket } from "@arcjet/node";
import { serve, type HttpBindings } from "@hono/node-server";
import { Hono } from "hono";
const aj = arcjet({
key: process.env.ARCJET_KEY,
rules: [
// Create a token bucket rate limit. Other algorithms are supported.
tokenBucket({
mode: "LIVE", // will block requests. Use "DRY_RUN" to log only
characteristics: ["userId"], // track requests by a custom user ID
refillRate: 5, // refill 5 tokens per interval
interval: 10, // refill every 10 seconds
capacity: 10, // bucket maximum capacity of 10 tokens
}),
],
});
const app = new Hono<{ Bindings: HttpBindings }>();
app.get("/", async (c) => {
const userId = "user123"; // Replace with your authenticated user ID
const decision = await aj.protect(c.env.incoming, { userId, requested: 5 }); // Deduct 5 tokens from the bucket
console.log("Arcjet decision", decision);
return c.json({
ok: true,
message: "Hello Hono!",
});
});
const port = 3000;
console.log(`Server is running on port ${port}`);
serve({
fetch: app.fetch,
port,
}); |
trunk-io bot
pushed a commit
that referenced
this issue
Apr 9, 2024
Closes #477 This adds an example to show how to use Hono with their Node.js Adapter and the Arcjet Node.js SDK. Note: This doesn't resolve the issue with Hono + Bun, since we'll need to investigate an SDK for Bun itself.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When trying to parse the IP from the headers in a Node.js Hono route, the
ip
method has a type error:This also errors when using
c.req.raw
which is aRequest
.Example:
The text was updated successfully, but these errors were encountered: