Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

Commit

Permalink
fix(express): ensure req.body is a string
Browse files Browse the repository at this point in the history
fix #15
  • Loading branch information
tripodsan committed Mar 25, 2019
1 parent 0ab15a5 commit c40897a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/expressify.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@ const serverless = require('serverless-http');

module.exports = function expressify(app) {
return async (params) => {
const handler = serverless(app, {
const requestBodyAdapter = async (req, res) => {
// `serverless-http` converts the request.body by default to a buffer,
// which not all express apps can deal with.
if (req.body && Buffer.isBuffer(req.body)) {
req.body = req.body.toString('utf-8');
}
return app(req, res);
};

const handler = serverless(requestBodyAdapter, {
// eslint-disable-next-line no-use-before-define
binary: BINARY_MEDIA_TYPES,
});
Expand Down

0 comments on commit c40897a

Please sign in to comment.