I made a netlify function that create a pdf. The code is as below.
exports.handler = (event, context, callback) => {
if (event.httpMethod !== "POST") {
return { statusCode: 405, body: "Method Not Allowed" };
}
const params = JSON.parse(event.body);
const templateName = params.templateName || "";
const datas = params.datas || [];
const token = params.token || "";
if (!checkToken(token)) {
return { statusCode: 403, body: "Invalid token" };
}
const arg = { ...templateData[templateName], datas, preview: true };
const docDefinition = pdfUtil.createDocDefinition(arg);
getBlob(docDefinition).then(blob => {
callback(null, {
headers: {
"Access-Control-Allow-Origin": "*",
"Content-Type": "application/pdf"
},
statusCode: 200,
body: blob.toString("base64"),
isBase64Encoded: true
});
});
};
This function is working on localhost but not in production. I receive the following error message
0:00:00 AM: error decoding lambda response: json: cannot unmarshal object into Go struct field lambdaInvokeResponse.body of type string
So, I found this discussion.
But, I don’t know what’s wrong.
Any idea what’s going on here?