Serverless-express: Response has undefined headers - Internal Server Error

Created on 28 Jan 2021  路  12Comments  路  Source: vendia/serverless-express

There is something happening between SERVERLESS_EXPRESS:FORWARD_RESPONSE:EVENT_SOURCE_RESPONSE and SERVERLESS_EXPRESS:FORWARD_RESPONSE:CONTENT_TYPE and SERVERLESS_EXPRESS:FORWARD_RESPONSE:HTTP_RESPONSE

The output back to the browser is

{
  "message": "Internal Server Error"
}

Debug Logs

2021-01-27T18:03:30.694Z e3cc35a9-58cb-433f-84bc-2e721658613d DEBUG {
message: 'SERVERLESS_EXPRESS:FORWARD_RESPONSE:EVENT_SOURCE_RESPONSE',
successResponse: {
statusCode: 302,
body: '',
headers: [Object: null prototype] {
vary: 'Origin',
'access-control-allow-credentials': 'true',
'x-dns-prefetch-control': 'off',
'expect-ct': 'max-age=0',
'x-frame-options': 'SAMEORIGIN',
'strict-transport-security': 'max-age=15552000; includeSubDomains',
'x-download-options': 'noopen',
'x-content-type-options': 'nosniff',
'x-permitted-cross-domain-policies': 'none',
'referrer-policy': 'same-origin',
'x-xss-protection': '0',
'set-cookie': [Array],
location: 'https://myapp.ai/
},
isBase64Encoded: false
}
}
2021-01-27T18:03:30.694Z e3cc35a9-58cb-433f-84bc-2e721658613d DEBUG {
message: 'SERVERLESS_EXPRESS:FORWARD_RESPONSE:CONTENT_TYPE',
contentType: ''
}
2021-01-27T18:03:30.694Z e3cc35a9-58cb-433f-84bc-2e721658613d DEBUG {
message: 'SERVERLESS_EXPRESS:FORWARD_RESPONSE:HTTP_RESPONSE',
headers: undefined,
statusCode: 302
}

All 12 comments

I'll take a look. Is the 302 expected? What event source is this?

Yes, I'm just trying to send a redirect with a location header.

What do you mean by this? What event source is this?

By event source I mean are you using API Gateway (V1 or V2?) or something else (Lambda@Edge)

Oh, API Gateway V2

That log info was incorrect. I've published @vendia/[email protected] which includes the actual headers that are used in the response. That might give more info? I'll try a 302 redirect myself later.

Redirect works for me... Here's what my final log looks like:

{
  message: 'SERVERLESS_EXPRESS:FORWARD_RESPONSE:EVENT_SOURCE_RESPONSE',
  successResponse: {
    statusCode: 302,
    body: '<p>Found. Redirecting to <a href="/sam">/sam</a></p>',
    headers: [Object: null prototype] {
      'x-powered-by': 'Express',
      'access-control-allow-origin': '*',
      location: '/sam',
      vary: 'Accept, Accept-Encoding',
      'content-type': 'text/html; charset=utf-8',
      'content-length': '52'
    },
    isBase64Encoded: false
  }
}

Thanks @brettstack, redirection is working with rc.10, also other headers are working as well.
However there seems to be an issue with setting cookies with api-gateway-v2. Will create an issue for that

Thanks @brettstack the logs seem to look better. However, I'm still getting the message

{
  "message": "Internal Server Error"
}

So I'm thinking it might be happening somewhere in my stack. But it's pretty suspicious because I don't see any other errors anywhere. I am also setting cookies so I'm curious if it's something to do with what @WarFox is talking about?

Sounds like it's a similar problem. I have added separate issue for cookie here #355

Thanks @WarFox!

I'm looking deeper now and it looks like at some point the response is turning into a base64 encoded body. And setting isBase64Encoded to true. Not sure if API Gateway V2 has anything special it needs to do for that or if it can handle it.

Nevermind, looking at the AWS Docs setting isBase64Encoded to true should be fine.

Shall we close this in favour of 355?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brikis98 picture brikis98  路  9Comments

denneulin picture denneulin  路  8Comments

muswain picture muswain  路  8Comments

sclark39 picture sclark39  路  7Comments

goldenbearkin picture goldenbearkin  路  9Comments