({ connection }: Pick<IncomingMessage, 'headers' | 'connection'>)
| 14 | export { getURLParams } from '@tinyhttp/req' |
| 15 | |
| 16 | const trustRemoteAddress = ({ connection }: Pick<IncomingMessage, 'headers' | 'connection'>) => { |
| 17 | const val = connection.remoteAddress |
| 18 | |
| 19 | if (typeof val === 'function') return val |
| 20 | |
| 21 | if (typeof val === 'boolean' && val === true) return () => true |
| 22 | |
| 23 | if (typeof val === 'number') return (_: unknown, i: number) => (val ? i < val : undefined) |
| 24 | |
| 25 | if (typeof val === 'string') return compile(val.split(',').map((x) => x.trim())) |
| 26 | |
| 27 | return compile(val || []) |
| 28 | } |
| 29 | |
| 30 | export const getRouteFromApp = ({ middleware }: App, h: Handler<Request, Response>) => |
| 31 | middleware.find(({ handler }) => typeof handler === 'function' && handler.name === h.name) |
no test coverage detected