diff options
author | 2021-08-13 00:45:01 +0530 | |
---|---|---|
committer | 2021-08-13 00:45:01 +0530 | |
commit | 2d27d5e66649d4f5baf127a53ee5ae524eae3a59 (patch) | |
tree | c592ea219ac8cd987fc367f57b54034c450ab2ab /src/internal-server/config/bodyParser.js | |
parent | Ferdi v5.6.0 (diff) | |
parent | 5.6.1-nightly.24 [skip ci] (diff) | |
download | ferdium-app-2d27d5e66649d4f5baf127a53ee5ae524eae3a59.tar.gz ferdium-app-2d27d5e66649d4f5baf127a53ee5ae524eae3a59.tar.zst ferdium-app-2d27d5e66649d4f5baf127a53ee5ae524eae3a59.zip |
chore: merge from nightly branch into release branch in prep for next beta
Diffstat (limited to 'src/internal-server/config/bodyParser.js')
-rw-r--r-- | src/internal-server/config/bodyParser.js | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/src/internal-server/config/bodyParser.js b/src/internal-server/config/bodyParser.js new file mode 100644 index 000000000..8a5406f9e --- /dev/null +++ b/src/internal-server/config/bodyParser.js | |||
@@ -0,0 +1,155 @@ | |||
1 | module.exports = { | ||
2 | /* | ||
3 | |-------------------------------------------------------------------------- | ||
4 | | JSON Parser | ||
5 | |-------------------------------------------------------------------------- | ||
6 | | | ||
7 | | Below settings are applied when the request body contains a JSON payload. | ||
8 | | If you want body parser to ignore JSON payloads, then simply set `types` | ||
9 | | to an empty array. | ||
10 | */ | ||
11 | json: { | ||
12 | /* | ||
13 | |-------------------------------------------------------------------------- | ||
14 | | limit | ||
15 | |-------------------------------------------------------------------------- | ||
16 | | | ||
17 | | Defines the limit of JSON that can be sent by the client. If payload | ||
18 | | is over 1mb it will not be processed. | ||
19 | | | ||
20 | */ | ||
21 | limit: '50mb', | ||
22 | |||
23 | /* | ||
24 | |-------------------------------------------------------------------------- | ||
25 | | strict | ||
26 | |-------------------------------------------------------------------------- | ||
27 | | | ||
28 | | When `strict` is set to true, body parser will only parse Arrays and | ||
29 | | Object. Otherwise everything parseable by `JSON.parse` is parsed. | ||
30 | | | ||
31 | */ | ||
32 | strict: true, | ||
33 | |||
34 | /* | ||
35 | |-------------------------------------------------------------------------- | ||
36 | | types | ||
37 | |-------------------------------------------------------------------------- | ||
38 | | | ||
39 | | Which content types are processed as JSON payloads. You are free to | ||
40 | | add your own types here, but the request body should be parseable | ||
41 | | by `JSON.parse` method. | ||
42 | | | ||
43 | */ | ||
44 | types: [ | ||
45 | 'application/json', | ||
46 | 'application/json-patch+json', | ||
47 | 'application/vnd.api+json', | ||
48 | 'application/csp-report', | ||
49 | ], | ||
50 | }, | ||
51 | |||
52 | /* | ||
53 | |-------------------------------------------------------------------------- | ||
54 | | Raw Parser | ||
55 | |-------------------------------------------------------------------------- | ||
56 | | | ||
57 | | | ||
58 | | | ||
59 | */ | ||
60 | raw: { | ||
61 | types: [ | ||
62 | 'text/*', | ||
63 | ], | ||
64 | }, | ||
65 | |||
66 | /* | ||
67 | |-------------------------------------------------------------------------- | ||
68 | | Form Parser | ||
69 | |-------------------------------------------------------------------------- | ||
70 | | | ||
71 | | | ||
72 | | | ||
73 | */ | ||
74 | form: { | ||
75 | types: [ | ||
76 | 'application/x-www-form-urlencoded', | ||
77 | ], | ||
78 | }, | ||
79 | |||
80 | /* | ||
81 | |-------------------------------------------------------------------------- | ||
82 | | Files Parser | ||
83 | |-------------------------------------------------------------------------- | ||
84 | | | ||
85 | | | ||
86 | | | ||
87 | */ | ||
88 | files: { | ||
89 | types: [ | ||
90 | 'multipart/form-data', | ||
91 | ], | ||
92 | |||
93 | /* | ||
94 | |-------------------------------------------------------------------------- | ||
95 | | Max Size | ||
96 | |-------------------------------------------------------------------------- | ||
97 | | | ||
98 | | Below value is the max size of all the files uploaded to the server. It | ||
99 | | is validated even before files have been processed and hard exception | ||
100 | | is thrown. | ||
101 | | | ||
102 | | Consider setting a reasonable value here, otherwise people may upload GB's | ||
103 | | of files which will keep your server busy. | ||
104 | | | ||
105 | | Also this value is considered when `autoProcess` is set to true. | ||
106 | | | ||
107 | */ | ||
108 | maxSize: '20mb', | ||
109 | |||
110 | /* | ||
111 | |-------------------------------------------------------------------------- | ||
112 | | Auto Process | ||
113 | |-------------------------------------------------------------------------- | ||
114 | | | ||
115 | | Whether or not to auto-process files. Since HTTP servers handle files via | ||
116 | | couple of specific endpoints. It is better to set this value off and | ||
117 | | manually process the files when required. | ||
118 | | | ||
119 | | This value can contain a boolean or an array of route patterns | ||
120 | | to be autoprocessed. | ||
121 | */ | ||
122 | autoProcess: true, | ||
123 | |||
124 | /* | ||
125 | |-------------------------------------------------------------------------- | ||
126 | | Process Manually | ||
127 | |-------------------------------------------------------------------------- | ||
128 | | | ||
129 | | The list of routes that should not process files and instead rely on | ||
130 | | manual process. This list should only contain routes when autoProcess | ||
131 | | is to true. Otherwise everything is processed manually. | ||
132 | | | ||
133 | */ | ||
134 | processManually: [], | ||
135 | |||
136 | /* | ||
137 | |-------------------------------------------------------------------------- | ||
138 | | Temporary file name | ||
139 | |-------------------------------------------------------------------------- | ||
140 | | | ||
141 | | Define a function, which should return a string to be used as the | ||
142 | | tmp file name. | ||
143 | | | ||
144 | | If not defined, Bodyparser will use `uuid` as the tmp file name. | ||
145 | | | ||
146 | | To be defined as. If you are defining the function, then do make sure | ||
147 | | to return a value from it. | ||
148 | | | ||
149 | | tmpFileName () { | ||
150 | | return 'some-unique-value' | ||
151 | | } | ||
152 | | | ||
153 | */ | ||
154 | }, | ||
155 | }; | ||