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()', () => {
17
17
statusCode : 200 ,
18
18
headers : {
19
19
'Cache-Control' : `public, max-age=${ 60 * 10 } ` ,
20
+ 'content-length' : '59' ,
20
21
'content-type' : 'application/json' ,
21
22
} ,
22
23
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'
6
6
7
7
export const aResponse = (
8
8
status : HttpStatusCode ,
9
- result : {
9
+ result ? : {
10
10
'@context' : URL
11
11
} & Record < string , unknown > ,
12
12
cacheForSeconds : number = 60 ,
13
13
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