Skip to content
Myr

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 file

Take it

feat(adapters): add the seven adapters as workspace packages (#5463)Yusuke Wadabefore adoptionb877827

lines 1–40why, one step back
1import type { Context } from 'hono'
2import type { GetConnInfo } from 'hono/conninfo'34/**5 * Netlify context type6 * @see https://docs.netlify.com/functions/api/7 */8type NetlifyContext = {9 ip?: string10 geo?: {11 city?: string12 country?: {13 code?: string14 name?: string15 }16 subdivision?: {17 code?: string18 name?: string19 }20 latitude?: number21 longitude?: number22 timezone?: string23 postalCode?: string24 }25 requestId?: string26}2728type Env = {29 Bindings: {30 context: NetlifyContext31 }32}3334/**35 * Get connection information from Netlify36 * @param c - Context37 * @returns Connection information including remote address38 * @example39 * ```ts40 * import { Hono } from 'hono'

feat(adapters/netlify): publish to JSR (#5468)Yusuke Wadabefore adoption72f0d8d

line 41why, one step back
41 * import { handle, getConnInfo } from '@hono/netlify'

feat(adapters): add the seven adapters as workspace packages (#5463)Yusuke Wadabefore adoptionb877827

lines 42–57why, one step back
42 *
43 * const app = new Hono()44 *45 * app.get('/', (c) => {46 * const info = getConnInfo(c)47 * return c.text(`Your IP: ${info.remote.address}`)48 * })49 *50 * export default handle(app)51 * ```52 */53export const getConnInfo: GetConnInfo = (c: Context<Env>) => ({54 remote: {55 address: c.env.context?.ip,56 },57})