0
0
mirror of https://github.com/honojs/hono.git synced 2024-11-24 19:26:56 +01:00

feat(vercel): add getConnInfo for vercel adapter (#3085)

This commit is contained in:
promer94 2024-07-08 22:46:56 +08:00 committed by GitHub
parent fbae337190
commit ce1c8172d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 0 deletions

View File

@ -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)
})
})

View File

@ -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',
},
})

View File

@ -4,3 +4,4 @@
*/
export { handle } from './handler'
export { getConnInfo } from './conninfo'