Skip to content

Commit 93f0a80

Browse files
authored
Merge pull request #958 from supabase/avallete/pgmeta-60-fastifyerror-request-body-is-too-large
fix(server): bump bodyLimit to 3MB default allow parameterize
2 parents 003391e + dd3e9ad commit 93f0a80

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/server/app.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@ import * as Sentry from '@sentry/node'
33
import cors from '@fastify/cors'
44
import swagger from '@fastify/swagger'
55
import { fastify, FastifyInstance, FastifyServerOptions } from 'fastify'
6-
import { PG_META_REQ_HEADER } from './constants.js'
6+
import { PG_META_REQ_HEADER, MAX_BODY_LIMIT } from './constants.js'
77
import routes from './routes/index.js'
88
import { extractRequestForLogging } from './utils.js'
99
// Pseudo package declared only for this module
1010
import pkg from '#package.json' with { type: 'json' }
1111

1212
export const build = (opts: FastifyServerOptions = {}): FastifyInstance => {
13-
const app = fastify({ disableRequestLogging: true, requestIdHeader: PG_META_REQ_HEADER, ...opts })
13+
const app = fastify({
14+
disableRequestLogging: true,
15+
requestIdHeader: PG_META_REQ_HEADER,
16+
bodyLimit: MAX_BODY_LIMIT,
17+
...opts,
18+
})
1419
Sentry.setupFastifyErrorHandler(app)
1520

1621
app.setErrorHandler((error, request, reply) => {

src/server/constants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ export const PG_META_MAX_RESULT_SIZE = process.env.PG_META_MAX_RESULT_SIZE_MB
5757
parseInt(process.env.PG_META_MAX_RESULT_SIZE_MB, 10) * 1024 * 1024
5858
: 2 * 1024 * 1024 * 1024 // default to 2GB max query size result
5959

60+
export const MAX_BODY_LIMIT = process.env.PG_META_MAX_BODY_LIMIT_MB
61+
? // Fastify server max body size allowed, is in bytes, convert from MB to Bytes
62+
parseInt(process.env.PG_META_MAX_BODY_LIMIT_MB, 10) * 1024 * 1024
63+
: 3 * 1024 * 1024
64+
6065
export const DEFAULT_POOL_CONFIG: PoolConfig = {
6166
max: 1,
6267
connectionTimeoutMillis: PG_CONN_TIMEOUT_SECS * 1000,

0 commit comments

Comments
 (0)