File tree Expand file tree Collapse file tree 2 files changed +16
-11
lines changed Expand file tree Collapse file tree 2 files changed +16
-11
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ void describe('aResponse()', () => {
1717 statusCode : 200 ,
1818 headers : {
1919 'Cache-Control' : `public, max-age=${ 60 * 10 } ` ,
20+ 'content-length' : '59' ,
2021 'content-type' : 'application/json' ,
2122 } ,
2223 body : JSON . stringify ( {
Original file line number Diff line number Diff line change @@ -6,18 +6,22 @@ import type { HttpStatusCode } from '@hello.nrfcloud.com/proto/hello'
66
77export const aResponse = (
88 status : HttpStatusCode ,
9- result : {
9+ result ? : {
1010 '@context' : URL
1111 } & Record < string , unknown > ,
1212 cacheForSeconds : number = 60 ,
1313 headers ?: APIGatewayProxyStructuredResultV2 [ 'headers' ] ,
14- ) : APIGatewayProxyResultV2 => ( {
15- statusCode : status ,
16- headers : {
17- 'content-type' : 'application/json' ,
18- 'Cache-Control' :
19- cacheForSeconds > 0 ? `public, max-age=${ cacheForSeconds } ` : 'no-store' ,
20- ...( headers ?? { } ) ,
21- } ,
22- body : JSON . stringify ( result ) ,
23- } )
14+ ) : APIGatewayProxyResultV2 => {
15+ const body = result !== undefined ? JSON . stringify ( result ) : undefined
16+ return {
17+ statusCode : status ,
18+ headers : {
19+ ...( body !== undefined ? { 'content-type' : 'application/json' } : { } ) ,
20+ 'content-length' : `${ body ?. length ?? 0 } ` ,
21+ 'Cache-Control' :
22+ cacheForSeconds > 0 ? `public, max-age=${ cacheForSeconds } ` : 'no-store' ,
23+ ...( headers ?? { } ) ,
24+ } ,
25+ body,
26+ }
27+ }
You can’t perform that action at this time.
0 commit comments