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