diff --git a/src/adapter/vercel/conninfo.test.ts b/src/adapter/vercel/conninfo.test.ts new file mode 100644 index 00000000..7d390af5 --- /dev/null +++ b/src/adapter/vercel/conninfo.test.ts @@ -0,0 +1,18 @@ +import { Context } from '../../context' +import { getConnInfo } from './conninfo' + +describe('getConnInfo', () => { + it('Should getConnInfo works', () => { + const address = Math.random().toString() + const req = new Request('http://localhost/', { + headers: { + 'x-real-ip': address, + }, + }) + const c = new Context(req) + + const info = getConnInfo(c) + + expect(info.remote.address).toBe(address) + }) +}) diff --git a/src/adapter/vercel/conninfo.ts b/src/adapter/vercel/conninfo.ts new file mode 100644 index 00000000..763af117 --- /dev/null +++ b/src/adapter/vercel/conninfo.ts @@ -0,0 +1,9 @@ +import type { GetConnInfo } from '../../helper/conninfo' + +export const getConnInfo: GetConnInfo = (c) => ({ + remote: { + // https://github.com/vercel/vercel/blob/b70bfb5fbf28a4650d4042ce68ca5c636d37cf44/packages/edge/src/edge-headers.ts#L10-L12C32 + address: c.req.header('x-real-ip'), + addressType: 'unknown', + }, +}) diff --git a/src/adapter/vercel/index.ts b/src/adapter/vercel/index.ts index 190bea70..796cfd1d 100644 --- a/src/adapter/vercel/index.ts +++ b/src/adapter/vercel/index.ts @@ -4,3 +4,4 @@ */ export { handle } from './handler' +export { getConnInfo } from './conninfo'