bodyParser.js 4.6 KB

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