conninfo.ts
This file
Path
adapters/netlify/src/conninfo.ts
57 lines 路 1.1 KiB 路 TypeScript
Last changed by
feat(adapters/netlify): publish to JSR (#5468)Yusuke Wadabefore adoption72f0d8d
History of this fileTake it
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758import type { Context } from 'hono'import type { GetConnInfo } from 'hono/conninfo'
/** * Netlify context type * @see https://docs.netlify.com/functions/api/ */type NetlifyContext = { ip?: string geo?: { city?: string country?: { code?: string name?: string } subdivision?: { code?: string name?: string } latitude?: number longitude?: number timezone?: string postalCode?: string } requestId?: string}
type Env = { Bindings: { context: NetlifyContext }}
/** * Get connection information from Netlify * @param c - Context * @returns Connection information including remote address * @example * ```ts * import { Hono } from 'hono' * import { handle, getConnInfo } from '@hono/netlify' * * const app = new Hono() * * app.get('/', (c) => { * const info = getConnInfo(c) * return c.text(`Your IP: ${info.remote.address}`) * }) * * export default handle(app) * ``` */export const getConnInfo: GetConnInfo = (c: Context<Env>) => ({ remote: { address: c.env.context?.ip, },})