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:
parent
fbae337190
commit
ce1c8172d9
18
src/adapter/vercel/conninfo.test.ts
Normal file
18
src/adapter/vercel/conninfo.test.ts
Normal 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)
|
||||
})
|
||||
})
|
9
src/adapter/vercel/conninfo.ts
Normal file
9
src/adapter/vercel/conninfo.ts
Normal 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',
|
||||
},
|
||||
})
|
@ -4,3 +4,4 @@
|
||||
*/
|
||||
|
||||
export { handle } from './handler'
|
||||
export { getConnInfo } from './conninfo'
|
||||
|
Loading…
Reference in New Issue
Block a user