@@ -11,11 +11,7 @@ process.env.NEW_RELIC_TRUSTED_ACCOUNT_KEY =
1111if ( process . env . LAMBDA_TASK_ROOT && typeof process . env . NEW_RELIC_SERVERLESS_MODE_ENABLED !== 'undefined' ) {
1212 delete process . env . NEW_RELIC_SERVERLESS_MODE_ENABLED
1313}
14- function getNestedHandler ( object , nestedProperty ) {
15- return nestedProperty . split ( '.' ) . reduce ( ( nested , key ) => {
16- return nested && nested [ key ]
17- } , object )
18- }
14+
1915function getHandlerPath ( ) {
2016 let handler
2117 const { NEW_RELIC_LAMBDA_HANDLER } = process . env
@@ -34,12 +30,9 @@ function getHandlerPath() {
3430 )
3531 }
3632
37- const lastSlashIndex = handler . lastIndexOf ( '/' ) + 1
38- const firstDotAfterSlash = handler . indexOf ( '.' , lastSlashIndex )
39- const moduleToImport = handler . slice ( 0 , firstDotAfterSlash )
40- const handlerToWrap = handler . slice ( firstDotAfterSlash + 1 )
41-
42- return { moduleToImport, handlerToWrap}
33+ const handlerToWrap = parts [ parts . length - 1 ]
34+ const moduleToImport = handler . slice ( 0 , handler . lastIndexOf ( '.' ) )
35+ return { moduleToImport, handlerToWrap }
4336}
4437
4538function handleRequireImportError ( e , moduleToImport ) {
@@ -102,8 +95,7 @@ const userHandler = await getHandler()
10295const handler = newrelic . setLambdaHandler ( userHandler )
10396
10497async function getHandler ( ) {
105- const userModule = await getModuleWithImport ( LAMBDA_TASK_ROOT , moduleToImport )
106- const userHandler = getNestedHandler ( userModule , handlerToWrap )
98+ const userHandler = ( await getModuleWithImport ( LAMBDA_TASK_ROOT , moduleToImport ) ) [ handlerToWrap ]
10799 validateHandlerDefinition ( userHandler , handlerToWrap , moduleToImport )
108100
109101 return userHandler
0 commit comments