Skip to content

Commit

Permalink
Add configurable raw limit
Browse files Browse the repository at this point in the history
Fixes: #245
Closes: #246

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Feb 10, 2021
1 parent ad75de7 commit 668ebe7
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions template/node12/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Alex Ellis 2017. All rights reserved.
// Copyright (c) OpenFaaS Author(s) 2020. All rights reserved.
// Copyright (c) Alex Ellis 2021. All rights reserved.
// Copyright (c) OpenFaaS Author(s) 2021. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

"use strict"
Expand All @@ -9,17 +9,18 @@ const app = express()
const handler = require('./function/handler');
const bodyParser = require('body-parser')

app.disable('x-powered-by');

if (process.env.RAW_BODY === 'true') {
app.use(bodyParser.raw({ type: '*/*' }))
var rawLimit = process.env.MAX_RAW_SIZE || '100kb' // body-parser default
app.use(bodyParser.raw({ type: '*/*' , limit: rawLimit }))
} else {
var jsonLimit = process.env.MAX_JSON_SIZE || '100kb' //body-parser default
app.use(bodyParser.json({ limit: jsonLimit}));
app.use(bodyParser.raw()); // "Content-Type: application/octet-stream"
app.use(bodyParser.text({ type : "text/*" }));
}

app.disable('x-powered-by');

class FunctionEvent {
constructor(req) {
this.body = req.body;
Expand Down Expand Up @@ -74,13 +75,17 @@ var middleware = async (req, res) => {
if (err) {
console.error(err);

return res.status(500).send(err.toString ? err.toString() : err);
return res.status(500)
.send(err.toString ? err.toString() : err);
}

if(isArray(functionResult) || isObject(functionResult)) {
res.set(fnContext.headers()).status(fnContext.status()).send(JSON.stringify(functionResult));
res.set(fnContext.headers())
.status(fnContext.status()).send(JSON.stringify(functionResult));
} else {
res.set(fnContext.headers()).status(fnContext.status()).send(functionResult);
res.set(fnContext.headers())
.status(fnContext.status())
.send(functionResult);
}
};

Expand Down

0 comments on commit 668ebe7

Please sign in to comment.