chore: incr bodyParser body limit (#2591)
This commit is contained in:
parent
e5f5358be0
commit
185fccad65
@ -1,6 +1,7 @@
|
|||||||
import supertest from 'supertest';
|
import supertest from 'supertest';
|
||||||
import { Application } from '../application';
|
import { Application } from '../application';
|
||||||
import { Plugin } from '../plugin';
|
import { Plugin } from '../plugin';
|
||||||
|
import longJson from './fixtures/long-json';
|
||||||
|
|
||||||
class MyPlugin extends Plugin {
|
class MyPlugin extends Plugin {
|
||||||
async load() {}
|
async load() {}
|
||||||
@ -29,6 +30,7 @@ describe('application', () => {
|
|||||||
dataWrapping: false,
|
dataWrapping: false,
|
||||||
registerActions: false,
|
registerActions: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
app.resourcer.registerActionHandlers({
|
app.resourcer.registerActionHandlers({
|
||||||
list: async (ctx, next) => {
|
list: async (ctx, next) => {
|
||||||
ctx.body = [1, 2];
|
ctx.body = [1, 2];
|
||||||
@ -50,6 +52,22 @@ describe('application', () => {
|
|||||||
return app.destroy();
|
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 () => {
|
it('resourcer.define', async () => {
|
||||||
app.resourcer.define({
|
app.resourcer.define({
|
||||||
name: 'test',
|
name: 'test',
|
||||||
|
11
packages/core/server/src/__tests__/fixtures/long-json.ts
Normal file
11
packages/core/server/src/__tests__/fixtures/long-json.ts
Normal 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;
|
||||||
|
}
|
@ -48,8 +48,12 @@ export function registerMiddlewares(app: Application, options: ApplicationOption
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (options.bodyParser !== false) {
|
if (options.bodyParser !== false) {
|
||||||
|
const bodyLimit = '10mb';
|
||||||
app.use(
|
app.use(
|
||||||
bodyParser({
|
bodyParser({
|
||||||
|
jsonLimit: bodyLimit,
|
||||||
|
formLimit: bodyLimit,
|
||||||
|
textLimit: bodyLimit,
|
||||||
...options.bodyParser,
|
...options.bodyParser,
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user