aboutsummaryrefslogtreecommitdiffstats
path: root/config/bodyparser.ts
diff options
context:
space:
mode:
Diffstat (limited to 'config/bodyparser.ts')
-rw-r--r--config/bodyparser.ts205
1 files changed, 205 insertions, 0 deletions
diff --git a/config/bodyparser.ts b/config/bodyparser.ts
new file mode 100644
index 0000000..b5adcda
--- /dev/null
+++ b/config/bodyparser.ts
@@ -0,0 +1,205 @@
1/**
2 * Config source: https://git.io/Jfefn
3 *
4 * Feel free to let us know via PR, if you find something broken in this config
5 * file.
6 */
7
8import { BodyParserConfig } from '@ioc:Adonis/Core/BodyParser';
9
10const bodyParserConfig: BodyParserConfig = {
11 /*
12 |--------------------------------------------------------------------------
13 | White listed methods
14 |--------------------------------------------------------------------------
15 |
16 | HTTP methods for which body parsing must be performed. It is a good practice
17 | to avoid body parsing for `GET` requests.
18 |
19 */
20 whitelistedMethods: ['POST', 'PUT', 'PATCH', 'DELETE'],
21
22 /*
23 |--------------------------------------------------------------------------
24 | JSON parser settings
25 |--------------------------------------------------------------------------
26 |
27 | The settings for the JSON parser. The types defines the request content
28 | types which gets processed by the JSON parser.
29 |
30 */
31 json: {
32 encoding: 'utf8',
33 limit: '1mb',
34 strict: true,
35 types: [
36 'application/json',
37 'application/json-patch+json',
38 'application/vnd.api+json',
39 'application/csp-report',
40 ],
41 },
42
43 /*
44 |--------------------------------------------------------------------------
45 | Form parser settings
46 |--------------------------------------------------------------------------
47 |
48 | The settings for the `application/x-www-form-urlencoded` parser. The types
49 | defines the request content types which gets processed by the form parser.
50 |
51 */
52 form: {
53 encoding: 'utf8',
54 limit: '1mb',
55 queryString: {},
56
57 /*
58 |--------------------------------------------------------------------------
59 | Convert empty strings to null
60 |--------------------------------------------------------------------------
61 |
62 | Convert empty form fields to null. HTML forms results in field string
63 | value when the field is left blank. This option normalizes all the blank
64 | field values to "null"
65 |
66 */
67 convertEmptyStringsToNull: true,
68
69 types: ['application/x-www-form-urlencoded'],
70 },
71
72 /*
73 |--------------------------------------------------------------------------
74 | Raw body parser settings
75 |--------------------------------------------------------------------------
76 |
77 | Raw body just reads the request body stream as a plain text, which you
78 | can process by hand. This must be used when request body type is not
79 | supported by the body parser.
80 |
81 */
82 raw: {
83 encoding: 'utf8',
84 limit: '1mb',
85 queryString: {},
86 types: ['text/*'],
87 },
88
89 /*
90 |--------------------------------------------------------------------------
91 | Multipart parser settings
92 |--------------------------------------------------------------------------
93 |
94 | The settings for the `multipart/form-data` parser. The types defines the
95 | request content types which gets processed by the form parser.
96 |
97 */
98 multipart: {
99 /*
100 |--------------------------------------------------------------------------
101 | Auto process
102 |--------------------------------------------------------------------------
103 |
104 | The auto process option will process uploaded files and writes them to
105 | the `tmp` folder. You can turn it off and then manually use the stream
106 | to pipe stream to a different destination.
107 |
108 | It is recommended to keep `autoProcess=true`. Unless you are processing bigger
109 | file sizes.
110 |
111 */
112 autoProcess: true,
113
114 /*
115 |--------------------------------------------------------------------------
116 | Files to be processed manually
117 |--------------------------------------------------------------------------
118 |
119 | You can turn off `autoProcess` for certain routes by defining
120 | routes inside the following array.
121 |
122 | NOTE: Make sure the route pattern starts with a leading slash.
123 |
124 | Correct
125 | ```js
126 | /projects/:id/file
127 | ```
128 |
129 | Incorrect
130 | ```js
131 | projects/:id/file
132 | ```
133 */
134 processManually: [],
135
136 /*
137 |--------------------------------------------------------------------------
138 | Temporary file name
139 |--------------------------------------------------------------------------
140 |
141 | When auto processing is on. We will use this method to compute the temporary
142 | file name. AdonisJs will compute a unique `tmpPath` for you automatically,
143 | However, you can also define your own custom method.
144 |
145 */
146 // tmpFileName () {
147 // },
148
149 /*
150 |--------------------------------------------------------------------------
151 | Encoding
152 |--------------------------------------------------------------------------
153 |
154 | Request body encoding
155 |
156 */
157 encoding: 'utf8',
158
159 /*
160 |--------------------------------------------------------------------------
161 | Convert empty strings to null
162 |--------------------------------------------------------------------------
163 |
164 | Convert empty form fields to null. HTML forms results in field string
165 | value when the field is left blank. This option normalizes all the blank
166 | field values to "null"
167 |
168 */
169 convertEmptyStringsToNull: true,
170
171 /*
172 |--------------------------------------------------------------------------
173 | Max Fields
174 |--------------------------------------------------------------------------
175 |
176 | The maximum number of fields allowed in the request body. The field includes
177 | text inputs and files both.
178 |
179 */
180 maxFields: 1000,
181
182 /*
183 |--------------------------------------------------------------------------
184 | Request body limit
185 |--------------------------------------------------------------------------
186 |
187 | The total limit to the multipart body. This includes all request files
188 | and fields data.
189 |
190 */
191 limit: '20mb',
192
193 /*
194 |--------------------------------------------------------------------------
195 | Types
196 |--------------------------------------------------------------------------
197 |
198 | The types that will be considered and parsed as multipart body.
199 |
200 */
201 types: ['multipart/form-data'],
202 },
203};
204
205export default bodyParserConfig;