bodyparser.ts 6.7 KB

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