File tree 2 files changed +37
-4
lines changed
2 files changed +37
-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,21 @@ process.on('message', async (msg) => {
48
48
...( env || { } ) ,
49
49
}
50
50
51
+ // We are not using lambda-local's environment variable setting because it cleans up
52
+ // environment vars to early (before stream is closed)
53
+ Object . keys ( environment ) . forEach ( function ( key ) {
54
+ if ( typeof process . env [ key ] !== 'undefined' ) {
55
+ envVarsToRestore [ key ] = process . env [ key ]
56
+ }
57
+ process . env [ key ] = environment [ key ]
58
+ } )
59
+
51
60
const response = await execute ( {
52
61
event : {
53
62
headers : headers || { } ,
54
63
httpMethod : httpMethod || 'GET' ,
55
64
rawUrl : new URL ( url || '/' , 'https://example.netlify' ) . href ,
56
65
} ,
57
- environment,
58
- envdestroy : true ,
59
66
lambdaFunc : { handler } ,
60
67
timeoutMs : 4_000 ,
61
68
} )
@@ -70,6 +77,14 @@ process.on('message', async (msg) => {
70
77
71
78
const bodyBuffer = await streamToBuffer ( response . body )
72
79
80
+ Object . keys ( environment ) . forEach ( function ( key ) {
81
+ if ( typeof envVarsToRestore [ key ] !== 'undefined' ) {
82
+ process . env [ key ] = envVarsToRestore [ key ]
83
+ } else {
84
+ delete process . env [ key ]
85
+ }
86
+ } )
87
+
73
88
const result = {
74
89
statusCode : response . statusCode ,
75
90
bodyBuffer,
You can’t perform that action at this time.
0 commit comments