From 5d6b4f7e6d6d19d37c7dfd55769b86fd50a9da39 Mon Sep 17 00:00:00 2001 From: Jonathan Price Date: Sun, 17 Oct 2021 20:46:38 +0100 Subject: [PATCH] handle binary responses that have been base64 encoded (#9) --- package-lock.json | 13 ++++++------- package.json | 2 +- src/local.lambda.ts | 3 ++- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 42c3294..a7727e0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,18 +1,19 @@ { "name": "ts-lambda-local-dev", - "version": "1.2.7", + "version": "1.4.2", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "1.2.7", + "name": "ts-lambda-local-dev", + "version": "1.4.2", "license": "MIT", "dependencies": { + "@types/aws-lambda": "^8.10.73", "http-method-enum": "^1.0.0", "ts-node-dev": "^1.1.6" }, "devDependencies": { - "@types/aws-lambda": "^8.10.73", "@types/node": "^14.14.37", "@typescript-eslint/eslint-plugin": "^4.20.0", "@typescript-eslint/parser": "^4.20.0", @@ -140,8 +141,7 @@ "node_modules/@types/aws-lambda": { "version": "8.10.73", "resolved": "https://registry.npmjs.org/@types/aws-lambda/-/aws-lambda-8.10.73.tgz", - "integrity": "sha512-P+a6TRQbRnVQOIjWkmw6F23wiJcF+4Uniasbzx7NAXjLQCVGx/Z4VoMfit81/pxlmcXNxAMGuYPugn6CrJLilQ==", - "dev": true + "integrity": "sha512-P+a6TRQbRnVQOIjWkmw6F23wiJcF+4Uniasbzx7NAXjLQCVGx/Z4VoMfit81/pxlmcXNxAMGuYPugn6CrJLilQ==" }, "node_modules/@types/json-schema": { "version": "7.0.7", @@ -2469,8 +2469,7 @@ "@types/aws-lambda": { "version": "8.10.73", "resolved": "https://registry.npmjs.org/@types/aws-lambda/-/aws-lambda-8.10.73.tgz", - "integrity": "sha512-P+a6TRQbRnVQOIjWkmw6F23wiJcF+4Uniasbzx7NAXjLQCVGx/Z4VoMfit81/pxlmcXNxAMGuYPugn6CrJLilQ==", - "dev": true + "integrity": "sha512-P+a6TRQbRnVQOIjWkmw6F23wiJcF+4Uniasbzx7NAXjLQCVGx/Z4VoMfit81/pxlmcXNxAMGuYPugn6CrJLilQ==" }, "@types/json-schema": { "version": "7.0.7", diff --git a/package.json b/package.json index da8a0ca..ae36138 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ts-lambda-local-dev", - "version": "1.4.1", + "version": "1.4.2", "description": "typescript lambda local development server", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/local.lambda.ts b/src/local.lambda.ts index 16ea441..27411b4 100644 --- a/src/local.lambda.ts +++ b/src/local.lambda.ts @@ -48,7 +48,8 @@ export class LocalLambda { this.enableCORS && this.setCORSHeaders(response); response.statusCode = rs.statusCode; response.writeHead(rs.statusCode, rs.headers); - response.end(rs.body); + const decodedResponseBody = Buffer.from(rs.body, rs.isBase64Encoded ? 'base64' : 'utf8'); + response.end(decodedResponseBody); }); });