File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
packages/api-server/src/plugins Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,23 @@ export const setLambdaFunctions = async (foundFunctions: string[]) => {
2828 const ts = Date . now ( )
2929 const routeName = path . basename ( fnPath ) . replace ( '.js' , '' )
3030
31- const { handler } = await import ( `file://${ fnPath } ` )
31+ const fnImport = await import ( `file://${ fnPath } ` )
32+ const handler : Handler = ( ( ) => {
33+ if ( 'handler' in fnImport ) {
34+ // ESModule export of handler - when using `export const handler = ...` - most common case
35+ return fnImport . handler
36+ }
37+ if ( 'default' in fnImport ) {
38+ if ( 'handler' in fnImport . default ) {
39+ // CommonJS export of handler - when using `module.exports.handler = ...` or `export default { handler: ... }`
40+ // This is less common, but required for bundling tools that export a default object, like esbuild or rollup
41+ return fnImport . default . handler
42+ }
43+ // Default export is not expected, so skip it
44+ }
45+ // If no handler is found, return undefined - we do not want to throw an error
46+ } ) ( )
47+
3248 LAMBDA_FUNCTIONS [ routeName ] = handler
3349 if ( ! handler ) {
3450 console . warn (
You can’t perform that action at this time.
0 commit comments