chore: incr bodyParser body limit (#2591)

This commit is contained in:
ChengLei Shao 2023-09-04 22:21:31 +08:00 committed by GitHub
parent e5f5358be0
commit 185fccad65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 0 deletions

View File

@ -1,6 +1,7 @@
import supertest from 'supertest';
import { Application } from '../application';
import { Plugin } from '../plugin';
import longJson from './fixtures/long-json';
class MyPlugin extends Plugin {
async load() {}
@ -29,6 +30,7 @@ describe('application', () => {
dataWrapping: false,
registerActions: false,
});
app.resourcer.registerActionHandlers({
list: async (ctx, next) => {
ctx.body = [1, 2];
@ -50,6 +52,22 @@ describe('application', () => {
return app.destroy();
});
it('should request long json', async () => {
app.resourcer.define({
name: 'test',
actions: {
test: async (ctx, next) => {
ctx.body = ctx.request.body;
await next();
},
},
});
const response = await agent.post('/api/test:test').send(longJson).set('Content-Type', 'application/json');
expect(response.statusCode).toBe(200);
});
it('resourcer.define', async () => {
app.resourcer.define({
name: 'test',

View File

@ -0,0 +1,11 @@
export default {
title: 'title',
content: getLongString(),
};
function getLongString() {
const size = 2 * 1024 * 1024;
const buffer = Buffer.alloc(size, 'a');
const str = buffer.toString('utf-8');
return str;
}

View File

@ -48,8 +48,12 @@ export function registerMiddlewares(app: Application, options: ApplicationOption
);
if (options.bodyParser !== false) {
const bodyLimit = '10mb';
app.use(
bodyParser({
jsonLimit: bodyLimit,
formLimit: bodyLimit,
textLimit: bodyLimit,
...options.bodyParser,
}),
{