AWS Lambda - Expressjs image serving issue when using serverless framework
serverless-http allows you to ‘wrap’ your API for serverless use. No HTTP server, no ports or sockets. Just your code in the same execution pipeline you are already familiar with.
Binary mode detection looks at the BINARY_CONTENT_TYPES environment variable, or you can specify an array of types, or a custom function:
In the following code snippet i allowed jpeg and png binary types. If you want to allow all file types you can ‘*/*’ as well
const app = require("./app");
const serverless = require("serverless-http");
const handler = serverless(app, {
binary: ["image/jpeg", "image/png"],
});
module.exports.request = async (event, context) => {
context.callbackWaitsForEmptyEventLoop = false;
const result = await handler(event, context);
return result;
};