aboutsummaryrefslogtreecommitdiffstats
path: root/config/bodyparser.ts
blob: b5adcdaa0e7a7ff4a8836daab2a51cb2b160fbb8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/**
 * Config source: https://git.io/Jfefn
 *
 * Feel free to let us know via PR, if you find something broken in this config
 * file.
 */

import { BodyParserConfig } from '@ioc:Adonis/Core/BodyParser';

const bodyParserConfig: BodyParserConfig = {
  /*
  |--------------------------------------------------------------------------
  | White listed methods
  |--------------------------------------------------------------------------
  |
  | HTTP methods for which body parsing must be performed. It is a good practice
  | to avoid body parsing for `GET` requests.
  |
  */
  whitelistedMethods: ['POST', 'PUT', 'PATCH', 'DELETE'],

  /*
  |--------------------------------------------------------------------------
  | JSON parser settings
  |--------------------------------------------------------------------------
  |
  | The settings for the JSON parser. The types defines the request content
  | types which gets processed by the JSON parser.
  |
  */
  json: {
    encoding: 'utf8',
    limit: '1mb',
    strict: true,
    types: [
      'application/json',
      'application/json-patch+json',
      'application/vnd.api+json',
      'application/csp-report',
    ],
  },

  /*
  |--------------------------------------------------------------------------
  | Form parser settings
  |--------------------------------------------------------------------------
  |
  | The settings for the `application/x-www-form-urlencoded` parser. The types
  | defines the request content types which gets processed by the form parser.
  |
  */
  form: {
    encoding: 'utf8',
    limit: '1mb',
    queryString: {},

    /*
    |--------------------------------------------------------------------------
    | Convert empty strings to null
    |--------------------------------------------------------------------------
    |
    | Convert empty form fields to null. HTML forms results in field string
    | value when the field is left blank. This option normalizes all the blank
    | field values to "null"
    |
    */
    convertEmptyStringsToNull: true,

    types: ['application/x-www-form-urlencoded'],
  },

  /*
  |--------------------------------------------------------------------------
  | Raw body parser settings
  |--------------------------------------------------------------------------
  |
  | Raw body just reads the request body stream as a plain text, which you
  | can process by hand. This must be used when request body type is not
  | supported by the body parser.
  |
  */
  raw: {
    encoding: 'utf8',
    limit: '1mb',
    queryString: {},
    types: ['text/*'],
  },

  /*
  |--------------------------------------------------------------------------
  | Multipart parser settings
  |--------------------------------------------------------------------------
  |
  | The settings for the `multipart/form-data` parser. The types defines the
  | request content types which gets processed by the form parser.
  |
  */
  multipart: {
    /*
    |--------------------------------------------------------------------------
    | Auto process
    |--------------------------------------------------------------------------
    |
    | The auto process option will process uploaded files and writes them to
    | the `tmp` folder. You can turn it off and then manually use the stream
    | to pipe stream to a different destination.
    |
    | It is recommended to keep `autoProcess=true`. Unless you are processing bigger
    | file sizes.
    |
    */
    autoProcess: true,

    /*
    |--------------------------------------------------------------------------
    | Files to be processed manually
    |--------------------------------------------------------------------------
    |
    | You can turn off `autoProcess` for certain routes by defining
    | routes inside the following array.
    |
    | NOTE: Make sure the route pattern starts with a leading slash.
    |
    | Correct
    | ```js
    | /projects/:id/file
    | ```
    |
    | Incorrect
    | ```js
    | projects/:id/file
    | ```
    */
    processManually: [],

    /*
    |--------------------------------------------------------------------------
    | Temporary file name
    |--------------------------------------------------------------------------
    |
    | When auto processing is on. We will use this method to compute the temporary
    | file name. AdonisJs will compute a unique `tmpPath` for you automatically,
    | However, you can also define your own custom method.
    |
    */
    // tmpFileName () {
    // },

    /*
    |--------------------------------------------------------------------------
    | Encoding
    |--------------------------------------------------------------------------
    |
    | Request body encoding
    |
    */
    encoding: 'utf8',

    /*
    |--------------------------------------------------------------------------
    | Convert empty strings to null
    |--------------------------------------------------------------------------
    |
    | Convert empty form fields to null. HTML forms results in field string
    | value when the field is left blank. This option normalizes all the blank
    | field values to "null"
    |
    */
    convertEmptyStringsToNull: true,

    /*
    |--------------------------------------------------------------------------
    | Max Fields
    |--------------------------------------------------------------------------
    |
    | The maximum number of fields allowed in the request body. The field includes
    | text inputs and files both.
    |
    */
    maxFields: 1000,

    /*
    |--------------------------------------------------------------------------
    | Request body limit
    |--------------------------------------------------------------------------
    |
    | The total limit to the multipart body. This includes all request files
    | and fields data.
    |
    */
    limit: '20mb',

    /*
    |--------------------------------------------------------------------------
    | Types
    |--------------------------------------------------------------------------
    |
    | The types that will be considered and parsed as multipart body.
    |
    */
    types: ['multipart/form-data'],
  },
};

export default bodyParserConfig;