Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/api-server/src/plugins/lambdaLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,23 @@ export const setLambdaFunctions = async (foundFunctions: string[]) => {
const ts = Date.now()
const routeName = path.basename(fnPath).replace('.js', '')

const { handler } = await import(`file://${fnPath}`)
const fnImport = await import(`file://${fnPath}`)
const handler: Handler = (() => {
if ('handler' in fnImport) {
// ESModule export of handler - when using `export const handler = ...` - most common case
return fnImport.handler
}
if ('default' in fnImport) {
if ('handler' in fnImport.default) {
// CommonJS export of handler - when using `module.exports.handler = ...` or `export default { handler: ... }`
// This is less common, but required for bundling tools that export a default object, like esbuild or rollup
return fnImport.default.handler
}
// Default export is not expected, so skip it
}
// If no handler is found, return undefined - we do not want to throw an error
})()

LAMBDA_FUNCTIONS[routeName] = handler
if (!handler) {
console.warn(
Expand Down
Loading