tethys.backend/config/bodyparser.ts

204 lines
5.9 KiB
TypeScript
Raw Permalink Normal View History

2023-03-03 15:54:28 +00:00
/**
* Config source: https://git.io/Jfefn
*
* Feel free to let us know via PR, if you find something broken in this config
* file.
*/
2024-03-14 19:25:27 +00:00
// import type { BodyParserConfig } from '@adonisjs/core/bodyparser';
import env from '#start/env';
import { defineConfig } from '@adonisjs/core/bodyparser';
2023-03-03 15:54:28 +00:00
2024-03-14 19:25:27 +00:00
const bodyParserConfig = defineConfig({
2023-03-03 15:54:28 +00:00
/*
2024-03-14 19:25:27 +00:00
|--------------------------------------------------------------------------
| White listed methods
|--------------------------------------------------------------------------
|
| HTTP methods for which body parsing must be performed. It is a good practice
| to avoid body parsing for `GET` requests.
|
*/
allowedMethods: ['POST', 'PUT', 'PATCH', 'DELETE'],
2023-03-03 15:54:28 +00:00
/*
2024-03-14 19:25:27 +00:00
|--------------------------------------------------------------------------
| JSON parser settings
|--------------------------------------------------------------------------
|
| The settings for the JSON parser. The types defines the request content
| types which gets processed by the JSON parser.
|
*/
2023-03-03 15:54:28 +00:00
json: {
encoding: 'utf-8',
limit: '1mb',
strict: true,
types: ['application/json', 'application/json-patch+json', 'application/vnd.api+json', 'application/csp-report'],
2023-03-03 15:54:28 +00:00
},
/*
2024-03-14 19:25:27 +00:00
|--------------------------------------------------------------------------
| 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.
|
*/
2023-03-03 15:54:28 +00:00
form: {
encoding: 'utf-8',
limit: '1mb',
queryString: {},
/*
2024-03-14 19:25:27 +00:00
|--------------------------------------------------------------------------
| 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"
|
*/
2023-03-03 15:54:28 +00:00
convertEmptyStringsToNull: true,
types: ['application/x-www-form-urlencoded'],
},
/*
2024-03-14 19:25:27 +00:00
|--------------------------------------------------------------------------
| 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.
|
*/
2023-03-03 15:54:28 +00:00
raw: {
encoding: 'utf-8',
limit: '1mb',
2024-03-14 19:25:27 +00:00
// queryString: {},
2023-03-03 15:54:28 +00:00
types: ['text/*'],
},
/*
2024-03-14 19:25:27 +00:00
|--------------------------------------------------------------------------
| 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.
|
*/
2023-03-03 15:54:28 +00:00
multipart: {
/*
2024-03-14 19:25:27 +00:00
|--------------------------------------------------------------------------
| 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.
|
*/
2023-03-03 15:54:28 +00:00
autoProcess: true,
/*
2024-03-14 19:25:27 +00:00
|--------------------------------------------------------------------------
| 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
| ```
*/
2023-03-03 15:54:28 +00:00
processManually: [],
/*
2024-03-14 19:25:27 +00:00
|--------------------------------------------------------------------------
| 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.
|
*/
2023-03-03 15:54:28 +00:00
// tmpFileName () {
// },
/*
2024-03-14 19:25:27 +00:00
|--------------------------------------------------------------------------
| Encoding
|--------------------------------------------------------------------------
|
| Request body encoding
|
*/
2023-03-03 15:54:28 +00:00
encoding: 'utf-8',
/*
2024-03-14 19:25:27 +00:00
|--------------------------------------------------------------------------
| 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"
|
*/
2023-03-03 15:54:28 +00:00
convertEmptyStringsToNull: true,
/*
2024-03-14 19:25:27 +00:00
|--------------------------------------------------------------------------
| Max Fields
|--------------------------------------------------------------------------
|
| The maximum number of fields allowed in the request body. The field includes
| text inputs and files both.
|
*/
2023-03-03 15:54:28 +00:00
maxFields: 1000,
/*
2024-03-14 19:25:27 +00:00
|--------------------------------------------------------------------------
| Request body limit
|--------------------------------------------------------------------------
|
| The total limit to the multipart body. This includes all request files
| and fields data.
|
*/
// limit: '20mb',
limit: env.get('UPLOAD_LIMIT', '513mb'),
2023-03-03 15:54:28 +00:00
/*
2024-03-14 19:25:27 +00:00
|--------------------------------------------------------------------------
| Types
|--------------------------------------------------------------------------
|
| The types that will be considered and parsed as multipart body.
|
*/
2023-03-03 15:54:28 +00:00
types: ['multipart/form-data'],
},
2024-03-14 19:25:27 +00:00
});
2023-03-03 15:54:28 +00:00
export default bodyParserConfig;