File tree 2 files changed +39
-4
lines changed
2 files changed +39
-4
lines changed Original file line number Diff line number Diff line change @@ -364,14 +364,24 @@ export async function invokeFunction(
364
364
NETLIFY_BLOBS_CONTEXT : createBlobContext ( ctx ) ,
365
365
...( env || { } ) ,
366
366
}
367
+
368
+ const envVarsToRestore = { }
369
+
370
+ // We are not using lambda-local's environment variable setting because it cleans up
371
+ // environment vars to early (before stream is closed)
372
+ Object . keys ( environment ) . forEach ( function ( key ) {
373
+ if ( typeof process . env [ key ] !== 'undefined' ) {
374
+ envVarsToRestore [ key ] = process . env [ key ]
375
+ }
376
+ process . env [ key ] = environment [ key ]
377
+ } )
378
+
367
379
const response = ( await execute ( {
368
380
event : {
369
381
headers : headers || { } ,
370
382
httpMethod : httpMethod || 'GET' ,
371
383
rawUrl : new URL ( url || '/' , 'https://example.netlify' ) . href ,
372
384
} ,
373
- environment,
374
- envdestroy : true ,
375
385
lambdaFunc : { handler } ,
376
386
timeoutMs : 4_000 ,
377
387
} ) ) as LambdaResponse
@@ -386,6 +396,14 @@ export async function invokeFunction(
386
396
387
397
const bodyBuffer = await streamToBuffer ( response . body )
388
398
399
+ Object . keys ( environment ) . forEach ( function ( key ) {
400
+ if ( typeof envVarsToRestore [ key ] !== 'undefined' ) {
401
+ process . env [ key ] = envVarsToRestore [ key ]
402
+ } else {
403
+ delete process . env [ key ]
404
+ }
405
+ } )
406
+
389
407
return {
390
408
statusCode : response . statusCode ,
391
409
bodyBuffer,
Original file line number Diff line number Diff line change @@ -48,14 +48,23 @@ process.on('message', async (msg) => {
48
48
...( env || { } ) ,
49
49
}
50
50
51
+ const envVarsToRestore = { }
52
+
53
+ // We are not using lambda-local's environment variable setting because it cleans up
54
+ // environment vars to early (before stream is closed)
55
+ Object . keys ( environment ) . forEach ( function ( key ) {
56
+ if ( typeof process . env [ key ] !== 'undefined' ) {
57
+ envVarsToRestore [ key ] = process . env [ key ]
58
+ }
59
+ process . env [ key ] = environment [ key ]
60
+ } )
61
+
51
62
const response = await execute ( {
52
63
event : {
53
64
headers : headers || { } ,
54
65
httpMethod : httpMethod || 'GET' ,
55
66
rawUrl : new URL ( url || '/' , 'https://example.netlify' ) . href ,
56
67
} ,
57
- environment,
58
- envdestroy : true ,
59
68
lambdaFunc : { handler } ,
60
69
timeoutMs : 4_000 ,
61
70
} )
@@ -70,6 +79,14 @@ process.on('message', async (msg) => {
70
79
71
80
const bodyBuffer = await streamToBuffer ( response . body )
72
81
82
+ Object . keys ( environment ) . forEach ( function ( key ) {
83
+ if ( typeof envVarsToRestore [ key ] !== 'undefined' ) {
84
+ process . env [ key ] = envVarsToRestore [ key ]
85
+ } else {
86
+ delete process . env [ key ]
87
+ }
88
+ } )
89
+
73
90
const result = {
74
91
statusCode : response . statusCode ,
75
92
bodyBuffer,
You can’t perform that action at this time.
0 commit comments