File size: 462 Bytes
c09f67c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import type { MiddlewareHandler } from "hono";
import type { Context } from "../types";
import { getClientIp } from "../utils/ip";

/**
 * Middleware that extracts client IP address and adds it to context
 * Handles proxies/load balancers correctly
 * Uses Hono's getConnInfo helper as fallback
 */
export const withClientIp: MiddlewareHandler<Context> = async (c, next) => {
  const clientIp = getClientIp(c);
  c.set("clientIp", clientIp);

  await next();
};