Skip to content

How to get client IP on Deno Deploy using Hono? #1791

Closed Answered by EdamAme-x
pappaa01 asked this question in Q&A
Discussion options

You must be logged in to vote

it works is here!

import { Hono } from 'https://deno.land/x/hono/mod.ts';

const app = new Hono();

app.get("/", (ctx) => {
  return ctx.body(ctx.env.remoteAddr().hostname);
});

const { serve } = Deno;

serve(async (request, connInfo) => {
  console.log(connInfo.remoteAddr)
  const remoteAddr = () => connInfo.remoteAddr;
  const env = { remoteAddr };
  return app.fetch(request, env);
}, {
  hostname: "0.0.0.0",
  port: 3000,
});

Replies: 1 comment 16 replies

Comment options

You must be logged in to vote
16 replies
@pappaa01
Comment options

@EdamAme-x
Comment options

@pappaa01
Comment options

@EdamAme-x
Comment options

Answer selected by pappaa01
@EdamAme-x
Comment options

@EdamAme-x
Comment options

@pappaa01
Comment options

@EdamAme-x
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants