Skip to content

Commit af6ff23

Browse files
Revert "feat: added code in esm for nested handler (#328)" (#415)
This reverts commit 45f9e9b.
1 parent abd8bdd commit af6ff23

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

nodejs/esm.mjs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ process.env.NEW_RELIC_TRUSTED_ACCOUNT_KEY =
1111
if (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+
1915
function 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

4538
function handleRequireImportError(e, moduleToImport) {
@@ -102,8 +95,7 @@ const userHandler = await getHandler()
10295
const handler = newrelic.setLambdaHandler(userHandler)
10396

10497
async 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

Comments
 (0)