@@ -32,6 +32,12 @@ function createCallback(response) {
32
32
if ( err ) {
33
33
return handleErr ( err , response ) ;
34
34
}
35
+ if ( lambdaResponse === undefined ) {
36
+ return handleErr (
37
+ "lambda response was undefined. check your function code again." ,
38
+ response
39
+ ) ;
40
+ }
35
41
if ( ! Number ( lambdaResponse . statusCode ) ) {
36
42
console . log (
37
43
`${ NETLIFYDEVERR } Your function response must have a numerical statusCode. You gave: $` ,
@@ -52,6 +58,7 @@ function createCallback(response) {
52
58
for ( const key in lambdaResponse . headers ) {
53
59
response . setHeader ( key , lambdaResponse . headers [ key ] ) ;
54
60
}
61
+ console . log ( { lambdaResponse } ) ;
55
62
response . write (
56
63
lambdaResponse . isBase64Encoded
57
64
? Buffer . from ( lambdaResponse . body , "base64" )
@@ -61,21 +68,6 @@ function createCallback(response) {
61
68
} ;
62
69
}
63
70
64
- function promiseCallback ( promise , callback ) {
65
- if ( ! promise ) return ;
66
- if ( typeof promise . then !== "function" ) return ;
67
- if ( typeof callback !== "function" ) return ;
68
-
69
- promise . then (
70
- function ( data ) {
71
- callback ( null , data ) ;
72
- } ,
73
- function ( err ) {
74
- callback ( err , null ) ;
75
- }
76
- ) ;
77
- }
78
-
79
71
// function getHandlerPath(functionPath) {
80
72
// if (functionPath.match(/\.js$/)) {
81
73
// return functionPath;
@@ -167,6 +159,11 @@ function createHandler(dir) {
167
159
try {
168
160
module . paths = [ moduleDir ] ;
169
161
handler = require ( functionPath ) ;
162
+ if ( typeof handler . handler !== "function" ) {
163
+ throw new Error (
164
+ `function ${ functionPath } must export a function named handler`
165
+ ) ;
166
+ }
170
167
module . paths = before ;
171
168
} catch ( error ) {
172
169
module . paths = before ;
@@ -200,6 +197,22 @@ function createHandler(dir) {
200
197
} ;
201
198
}
202
199
200
+ function promiseCallback ( promise , callback ) {
201
+ if ( ! promise ) return ; // means no handler was written
202
+ if ( typeof promise . then !== "function" ) return ;
203
+ if ( typeof callback !== "function" ) return ;
204
+
205
+ promise . then (
206
+ function ( data ) {
207
+ console . log ( "hellooo" ) ;
208
+ callback ( null , data ) ;
209
+ } ,
210
+ function ( err ) {
211
+ callback ( err , null ) ;
212
+ }
213
+ ) ;
214
+ }
215
+
203
216
async function serveFunctions ( settings ) {
204
217
const app = express ( ) ;
205
218
const dir = settings . functionsDir ;
0 commit comments