DefinitelyTyped/types/request-ip/index.d.ts
Łukasz Jagodziński 9264f705a6
The getClientIp can return null (#41902)
As you can see in the source code here https://github.com/pbojinov/request-ip/blob/master/src/index.js#L129 the `getClientIp` function can return `null` value if all the possible methods fail.
2020-02-04 08:53:37 -08:00

52 lines
1.1 KiB
TypeScript

// Type definitions for request-ip
// Project: https://github.com/pbojinov/request-ip
// Definitions by: Adam Babcock <https://github.com/mrhen>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="node" />
import * as http from 'http';
interface RequestHeaders extends http.IncomingHttpHeaders {
'x-client-ip'?: string;
'x-forwarded-for'?: string;
'x-real-ip'?: string;
'x-cluster-client-ip'?: string;
'x-forwarded'?: string;
'forwarded-for'?: string;
'forwarded'?: string;
}
interface Request {
headers: RequestHeaders;
connection: {
remoteAddress?: string;
socket?: {
remoteAddress?: string
};
};
info?: {
remoteAddress?: string
};
socket?: {
remoteAddress?: string
};
}
interface Options {
attributeName: string;
}
export declare function getClientIp(req: Request): string | null;
export function mw(options?: Options): (req: Request, res: any, next: any) => any;
declare global {
namespace Express {
interface Request {
clientIp?: string;
}
}
}