H
Honomathys

Client ip

How can I get the client ip, I need it for my rate limiter
Nico
Nico24d ago
What runtime are you using?
mathys
mathys24d ago
Bun.sh
Nico
Nico24d ago
It's not supported in Hono directly, bun you can do this
import app from './app';

Bun.serve({
fetch(req, res) {
globalThis.ip = res.requestIP(req);
return app.fetch(req, res)

},
});
import app from './app';

Bun.serve({
fetch(req, res) {
globalThis.ip = res.requestIP(req);
return app.fetch(req, res)

},
});
You can acess it with globalThis.ip. Until it's supported in Hono this is the best way @mathys Forget that I found a much better way
import app from './app';

Bun.serve({
fetch(req, server) {
return app.fetch(req, { ip: server.requestIP(req)})

},
});
import app from './app';

Bun.serve({
fetch(req, server) {
return app.fetch(req, { ip: server.requestIP(req)})

},
});
Now you can access it in c.env
mathys
mathys23d ago
@Nico it's working for me with this return
{
address: "::1",
family: "IPv6",
port: 64615,
}
{
address: "::1",
family: "IPv6",
port: 64615,
}
I think you should add this to the doc maybe
Nico
Nico23d ago
Perfect, once it’s live it will show an ip ::1 is just localhost. Or if you use another device you should see it And I will add it to the docs
mathys
mathys23d ago
Thanks again for the help
Want results from more Discord servers?
Add your server
More Posts
What is the best way to handle the error?What I want is to get the error from server to client using rpc + react query 1. Using `trycatch` 2Running `bun run dev` on a newly created Cloudflare Pages example spits an error``` bun run dev $ vite (!) Could not auto-determine entry point from rollupOptions or html files andconnect my hono application endpoints with swagger uihow i can use swagger ui with my hono applicationHow to set "credentials: true" in client side using rpc?I'm using rpc with react query on the client side, this kind of fetching has already credentials: trCookies doesn't processWhen I try to run in my middleware the following ``` setCookie(c, 'test', 'res', { maxAge: 60 * 60 use Context to get vars from wrangler.tomlhow can fix this code. i want to use my openaiApiKey from the wrangler.toml when i create an openai Connect Hono Cloudflare with MongoDBHi. I am using Hono and deploying to Cloudflare. However I am unable to find a way to connect mongodCase insensitive query paramsWe are using hono-zod-openapi to replace an existing API. Sadly the old API (written in ASP.Net) appPassword hashingHow to hash password?How to setup Hono with Remix/Cloudflare for Vite dev server?From the documentation for Cloudflare Pages, there is an adapter and a plugin, but it is not clear hValidate response objectsUsing the zod validator middleware it is possible to validate params , query, request body like: ``Hono Oauth Provider with JWT issueHey everyone! I'm not sure if this is the right place for me to post about this but recently I wanteDeploy Hono / Bun APII know, I know this is such a newby question but I come from small express apps and other simple ‘clIs there a way to list all request headers ?I have this use case where I am not sure which header key is being sent, I would like to log all heaTyping Middleware JWT and othersCurrently I am trying to type the `c.get('jwtPayload')` that is documented [here](https://hono.dev/mHow to generate openapi.yaml spec with Zod OpenAPI Hono?Is it possible to generate the openapi.yaml spec with Zod OpenAPI Hono from the commandline using a Why use Hono for Next.js backend (route handlers)?I'm creating a full-stack web app and probably using Next.js API/route handler: https://nextjs.org/dContext not finalizedIm trying to build a S3 API and it returns this on every requests ```js Error: Context is not finalType checking with Hono + prisma + zod -> return json date (expect string)HI, i m usin openAPi I declared return params in my route ``` const getUserRoute = createRoute({ Deploying Hono App to Multiple RuntimesHow can I deploy my Hono app to multiple different runtimes simultaneously within the same project?