serverless-aws-lambda
Version:
AWS Application Load Balancer and API Gateway - Lambda dev tool for Serverless. Allows Express synthax in handlers. Supports packaging, local invoking and offline ALB, APG, S3, SNS, SQS, DynamoDB Stream server mocking.
2 lines (1 loc) • 1.14 kB
JavaScript
var f=(o,c)=>{let a=[],t={};o.isBase64Encoded&&(o.body=Buffer.from(o.body,"base64").toString("utf-8"));let r=o.headers?.["content-type"],l=r?.split("=")[1];if(l){let s={};o.body.split(l).forEach(e=>{/filename=".+"/g.test(e)?s[e.match(/name=".+";/g)[0].slice(6,-2)]={type:"file",filename:e.match(/filename=".+"/g)[0].slice(10,-1),contentType:e.match(/Content-Type:\s.+/g)[0].slice(14),content:c?Buffer.from(e.slice(e.search(/Content-Type:\s.+/g)+e.match(/Content-Type:\s.+/g)[0].length+4,-4),"binary"):e.slice(e.search(/Content-Type:\s.+/g)+e.match(/Content-Type:\s.+/g)[0].length+4,-4)}:/name=".+"/g.test(e)&&(s[e.match(/name=".+"/g)[0].slice(6,-1)]=e.slice(e.search(/name=".+"/g)+e.match(/name=".+"/g)[0].length+4,-4))});for(let[e,n]of Object.entries(s))typeof n=="string"?t[e]=n:n&&typeof n=="object"&&a.push({name:e,...n})}else r=="application/x-www-form-urlencoded"&&(o.body.split("&").forEach(s=>{let[e,n]=s.split("=");t[decodeURIComponent(e)]=decodeURIComponent(n)}),o.body=t);return{files:a,body:t}},y=(o,c,a)=>{try{let t=f(o,!0);o.files=t.files,o.body=t.body,o.isBase64Encoded=!1}catch{}a()},p=y;export{y as bodyParser,p as default};