@@ -174,20 +174,25 @@ function createHandler(dir) {
174
174
return ;
175
175
}
176
176
177
- const isBase64 =
178
- request . body &&
179
- ! ( request . headers [ "content-type" ] || "" ) . match (
180
- / t e x t | a p p l i c a t i o n | m u l t i p a r t \/ f o r m - d a t a /
181
- ) ;
177
+ var isBase64Encoded = false ;
178
+ var body = request . body ;
179
+
180
+ if ( body instanceof Buffer ) {
181
+ isBase64Encoded = true ;
182
+ body = body . toString ( "base64" ) ;
183
+ } else if ( typeof ( body ) === "string" ) {
184
+ // body is already processed as string
185
+ } else {
186
+ body = "" ;
187
+ }
188
+
182
189
const lambdaRequest = {
183
190
path : request . path ,
184
191
httpMethod : request . method ,
185
192
queryStringParameters : queryString . parse ( request . url . split ( / \? ( .+ ) / ) [ 1 ] ) ,
186
193
headers : request . headers ,
187
- body : isBase64
188
- ? Buffer . from ( request . body . toString ( ) , "utf8" ) . toString ( "base64" )
189
- : request . body ,
190
- isBase64Encoded : isBase64
194
+ body : body ,
195
+ isBase64Encoded : isBase64Encoded
191
196
} ;
192
197
193
198
const callback = createCallback ( response ) ;
@@ -207,8 +212,8 @@ async function serveFunctions(settings) {
207
212
port : assignLoudly ( settings . port , defaultPort )
208
213
} ) ;
209
214
210
- app . use ( bodyParser . raw ( { limit : "6mb" } ) ) ;
211
- app . use ( bodyParser . text ( { limit : "6mb" , type : "*/*" } ) ) ;
215
+ app . use ( bodyParser . text ( { limit : "6mb" , type : [ "text/*" , "application/json" , "multipart/form-data" ] } ) ) ;
216
+ app . use ( bodyParser . raw ( { limit : "6mb" , type : "*/*" } ) ) ;
212
217
app . use (
213
218
expressLogging ( console , {
214
219
blacklist : [ "/favicon.ico" ]
0 commit comments