Skip to content

Commit ede6f44

Browse files
committed
Use TS Nullish Coalescing feature
1 parent cb9df92 commit ede6f44

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/eventToRequestOptions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const eventToRequestOptions = (event: APIGatewayEvent, ctx?: LambdaContext): InP
2828
if (ctx) {
2929
headers['x-aws-lambda-request-id'] = ctx.awsRequestId;
3030
}
31-
if (event.requestContext && event.requestContext.elb) {
31+
if (event.requestContext?.elb) {
3232
//load balancer request - it has the client ip in x-forwarded-for header
3333
if (typeof headers['x-forwarded-for'] === 'string') {
3434
const ips = headers['x-forwarded-for'].split(',').map(ip => ip.trim());
@@ -49,8 +49,8 @@ const eventToRequestOptions = (event: APIGatewayEvent, ctx?: LambdaContext): InP
4949
// api gateway request
5050
ssl = true;
5151
const remoteAddressList =
52-
event?.requestContext?.identity?.sourceIp ||
53-
event?.requestContext?.http?.sourceIp
52+
event.requestContext?.identity?.sourceIp ||
53+
event.requestContext?.http?.sourceIp
5454
if (remoteAddressList) {
5555
// HTTP API includes the full x-forwarder for chain here and the remote ip is the last element
5656
const items = remoteAddressList.split(',').map(s => s.trim());
@@ -59,7 +59,7 @@ const eventToRequestOptions = (event: APIGatewayEvent, ctx?: LambdaContext): InP
5959
}
6060
let method: string | undefined= event.httpMethod;
6161
let path: string | undefined = event.path;
62-
if (event.requestContext && typeof event.requestContext.http === 'object') {
62+
if (typeof event.requestContext?.http === 'object') {
6363
method = event.requestContext.http.method
6464
path = event.requestContext.http.path
6565
}

0 commit comments

Comments
 (0)