Skip to content

Commit a15c7aa

Browse files
committed
feat: added functionality to handle nested handlers
1 parent c3e2d64 commit a15c7aa

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

nodejs/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ const newrelic = require('newrelic')
1414
const fs = require('node:fs')
1515
const path = require('node:path')
1616

17+
function getModulePath(handler) {
18+
const lastSlashIndex = handler.lastIndexOf('/') + 1
19+
const firstDotAfterSlash = handler.indexOf('.', lastSlashIndex)
20+
return handler.slice(0, firstDotAfterSlash)
21+
}
22+
1723
function getHandlerPath() {
1824
let handler
1925
const { NEW_RELIC_LAMBDA_HANDLER } = process.env
@@ -32,8 +38,9 @@ function getHandlerPath() {
3238
)
3339
}
3440

35-
const handlerToWrap = parts[parts.length - 1]
36-
const moduleToImport = handler.slice(0, handler.lastIndexOf('.'))
41+
let prefixIndex = handler.lastIndexOf('/') !== -1 ? handler.lastIndexOf('/') + 1 : 0
42+
const handlerToWrap = handler.slice(prefixIndex).split('.').slice(1).join('.')
43+
const moduleToImport = getModulePath(handler)
3744
return { moduleToImport, handlerToWrap }
3845
}
3946

0 commit comments

Comments
 (0)