Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configurable raw limit #247

Merged
merged 1 commit into from
Feb 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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