Files
SnowLuma/.pnpm-store/v11/files/0e/c345f595d48e8b768d804311e473029adbd50b57adeac092243c3046b09b268dcf9924c55c8a5189977e92c897c9afc6f7682c426b77054c11c23b2db4d59c
TanTan 2a69b23b47
Dev Build / cleanup (push) Canceled after 0s
Dev Build / typecheck (push) Canceled after 0s
Dev Build / build (linux-arm64, ubuntu-24.04-arm, linux-arm64) (push) Canceled after 0s
Dev Build / build (linux-x64, ubuntu-latest, linux-x64) (push) Canceled after 0s
Dev Build / build (win-x64, windows-latest, win32-x64) (push) Canceled after 0s
Dev Build / dispatch-dev-docker (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

45 lines
1.4 KiB
Plaintext

Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
//#region src/adapter/aws-lambda/conninfo.ts
/**
* Get connection information from AWS Lambda
*
* Extracts client IP from various Lambda event sources:
* - API Gateway v1 (REST API): requestContext.identity.sourceIp
* - API Gateway v2 (HTTP API/Function URLs): requestContext.http.sourceIp
* - ALB: Falls back to x-forwarded-for header
*
* @param c - Context
* @returns Connection information including remote address
* @example
* ```ts
* import { Hono } from 'hono'
* import { handle, getConnInfo } from 'hono/aws-lambda'
*
* const app = new Hono()
*
* app.get('/', (c) => {
* const info = getConnInfo(c)
* return c.text(`Your IP: ${info.remote.address}`)
* })
*
* export const handler = handle(app)
* ```
* @deprecated `hono/aws-lambda` will be removed in v5. Install `@hono/aws-lambda` and import from there instead.
*/
const getConnInfo = (c) => {
const requestContext = c.env.requestContext;
let address;
if ("identity" in requestContext && requestContext.identity?.sourceIp) address = requestContext.identity.sourceIp;
else if ("http" in requestContext && requestContext.http?.sourceIp) address = requestContext.http.sourceIp;
else {
const xff = c.req.header("x-forwarded-for");
if (xff) {
const ips = xff.split(",");
address = ips[ips.length - 1].trim();
}
}
return { remote: { address } };
};
//#endregion
exports.getConnInfo = getConnInfo;