Skip to content

Commit

Permalink
fix: log actual headers in SERVERLESS_EXPRESS:FORWARD_RESPONSE:EVENT_…
Browse files Browse the repository at this point in the history
…SOURCE_RESPONSE_PARAMS
  • Loading branch information
brett-vendia committed Jan 28, 2021
1 parent ebd6a28 commit 72f2ef5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/basic-starter-api-gateway-v2/app.local.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const app = require('./app')
const app = require('./src/app')
const port = 3000

app.listen(port)
Expand Down
2 changes: 1 addition & 1 deletion src/event-sources/aws/api-gateway-v2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const url = require('url')
const { getResponseToService, getEventBody } = require('../utils')
const { getEventBody } = require('../utils')

function getRequestValuesFromApiGatewayEvent ({ event }) {
const {
Expand Down
17 changes: 11 additions & 6 deletions src/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,24 @@ function forwardResponse ({
eventResponseMapperFn,
log
}) {
log.debug('SERVERLESS_EXPRESS:FORWARD_RESPONSE:HTTP_RESPONSE', {
headers: response.headers,
statusCode: response.statusCode
})
const statusCode = response.statusCode
const headers = Response.headers(response)
const contentType = getContentType({
contentTypeHeader: headers['content-type']
})
log.debug('SERVERLESS_EXPRESS:FORWARD_RESPONSE:CONTENT_TYPE', { contentType })
const isBase64Encoded = isContentTypeBinaryMimeType({
contentType,
binaryMimeTypes
})
const body = Response.body(response).toString(isBase64Encoded ? 'base64' : 'utf8')

log.debug('SERVERLESS_EXPRESS:FORWARD_RESPONSE:EVENT_SOURCE_RESPONSE_PARAMS', {
statusCode,
body,
headers,
isBase64Encoded
})

const successResponse = eventResponseMapperFn({
statusCode,
body,
Expand All @@ -43,6 +46,7 @@ function forwardResponse ({
})

log.debug('SERVERLESS_EXPRESS:FORWARD_RESPONSE:EVENT_SOURCE_RESPONSE', { successResponse })

resolver.succeed({
response: successResponse
})
Expand Down Expand Up @@ -81,8 +85,9 @@ async function forwardRequestToNodeServer ({
}) {
const eventResponseMapperFn = eventFns.response
const requestValues = eventFns.getRequestValues({ event, context, log })
log.debug('SERVERLESS_EXPRESS:REQUEST_VALUES', { requestValues })
log.debug('SERVERLESS_EXPRESS:FORWARD_REQUEST_TO_NODE_SERVER:REQUEST_VALUES', { requestValues })
const response = await framework.sendRequest({ app, requestValues })
log.debug('SERVERLESS_EXPRESS:FORWARD_REQUEST_TO_NODE_SERVER:RESPONSE', { response })
forwardResponse({
binaryMimeTypes,
response,
Expand Down

0 comments on commit 72f2ef5

Please sign in to comment.