Added support for setting bodyParser limit param via environment variable (#1618)

In the NodeJs environment, the body-parser was set to 1MB, this change makes it configurable with an env variable.
This commit is contained in:
Rahul Bhati
2020-05-24 00:16:03 +05:30
committed by GitHub
parent d4e1cd4f1e
commit 9dd084810f
7 changed files with 157 additions and 4 deletions
+6 -4
View File
@@ -99,10 +99,12 @@ function specialize(req, res) {
// Request logger
app.use(morgan('combined'));
app.use(bodyParser.urlencoded({ extended: false, limit: '1mb' }));
app.use(bodyParser.json({limit: '1mb'}));
app.use(bodyParser.raw({limit: '1mb'}));
app.use(bodyParser.text({ type : "text/*", limit: '1mb' }));
let bodyParserLimit = process.env.BODY_PARSER_LIMIT || '1mb';
app.use(bodyParser.urlencoded({ extended: false, limit: bodyParserLimit}));
app.use(bodyParser.json({limit: bodyParserLimit}));
app.use(bodyParser.raw({limit: bodyParserLimit}));
app.use(bodyParser.text({ type : "text/*", limit: bodyParserLimit }));
app.post('/specialize', withEnsureGeneric(specialize));
app.post('/v2/specialize', withEnsureGeneric(specializeV2));
@@ -0,0 +1,11 @@
const process = require("process");
module.exports = async function (context) {
let message =
"BODY_PARSER_LIMIT received from env variable " +
process.env.BODY_PARSER_LIMIT;
return {
status: 200,
body: message,
};
};
@@ -0,0 +1,16 @@
{
"name": "fission-nodejs-bodyParser-example",
"version": "0.1.0",
"author": "Rahul Bhati",
"contributors": [
{
"name": "Rahul Bhati",
"email": "rjbhati009@gmail.com"
}
],
"description": "Nodejs example for setting bodyParser limit param via environment variable",
"engines": {
"node": ">=7.6.0"
},
"dependencies": {}
}
@@ -0,0 +1,42 @@
Fission Specs
=============
This is a set of specifications for a Fission app. This includes functions,
environments, and triggers; we collectively call these things "resources".
How to use these specs
----------------------
These specs are handled with the 'fission spec' command. See 'fission spec --help'.
'fission spec apply' will "apply" all resources specified in this directory to your
cluster. That means it checks what resources exist on your cluster, what resources are
specified in the specs directory, and reconciles the difference by creating, updating or
deleting resources on the cluster.
'fission spec apply' will also package up your source code (or compiled binaries) and
upload the archives to the cluster if needed. It uses 'ArchiveUploadSpec' resources in
this directory to figure out which files to archive.
You can use 'fission spec apply --watch' to watch for file changes and continuously keep
the cluster updated.
You can add YAMLs to this directory by writing them manually, but it's easier to generate
them. Use 'fission function create --spec' to generate a function spec,
'fission environment create --spec' to generate an environment spec, and so on.
You can edit any of the files in this directory, except 'fission-deployment-config.yaml',
which contains a UID that you should never change. To apply your changes simply use
'fission spec apply'.
fission-deployment-config.yaml
------------------------------
fission-deployment-config.yaml contains a UID. This UID is what fission uses to correlate
resources on the cluster to resources in this directory.
All resources created by 'fission spec apply' are annotated with this UID. Resources on
the cluster that are _not_ annotated with this UID are never modified or deleted by
fission.
@@ -0,0 +1,21 @@
apiVersion: fission.io/v1
kind: Environment
metadata:
creationTimestamp: null
name: node
namespace: default
spec:
builder:
command: build
image: fission/node-builder:latest
imagepullsecret: ""
keeparchive: false
poolsize: 3
resources: {}
runtime:
image: fission/node-env:latest
container:
env:
- name: BODY_PARSER_LIMIT
value: 100mb
version: 2
@@ -0,0 +1,7 @@
# This file is generated by the 'fission spec init' command.
# See the README in this directory for background and usage information.
# Do not edit the UID below: that will break 'fission spec apply'
apiVersion: fission.io/v1
kind: DeploymentConfig
name: node-spec
uid: 7a2704fb-6cff-4b4a-b5f8-71fe73365538
@@ -0,0 +1,54 @@
include:
- hello/*
kind: ArchiveUploadSpec
name: hello-dBc6
---
apiVersion: fission.io/v1
kind: Package
metadata:
creationTimestamp: null
name: hello-a98928ed-6b06-482f-9eb5-541540e714b1
namespace: default
spec:
deployment:
checksum: {}
environment:
name: node
namespace: default
source:
checksum: {}
type: url
url: archive://hello-dBc6
status:
buildstatus: pending
lastUpdateTimestamp: "2020-05-20T14:12:17Z"
---
apiVersion: fission.io/v1
kind: Function
metadata:
creationTimestamp: null
name: hello
namespace: default
spec:
InvokeStrategy:
ExecutionStrategy:
ExecutorType: poolmgr
MaxScale: 0
MinScale: 0
SpecializationTimeout: 120
TargetCPUPercent: 0
StrategyType: execution
configmaps: null
environment:
name: node
namespace: default
functionTimeout: 60
package:
functionName: hello
packageref:
name: hello-a98928ed-6b06-482f-9eb5-541540e714b1
namespace: default
resources: {}
secrets: null