Skip to content

fix(server): bump bodyLimit to 3MB default allow parameterize #958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ import * as Sentry from '@sentry/node'
import cors from '@fastify/cors'
import swagger from '@fastify/swagger'
import { fastify, FastifyInstance, FastifyServerOptions } from 'fastify'
import { PG_META_REQ_HEADER } from './constants.js'
import { PG_META_REQ_HEADER, MAX_BODY_LIMIT } from './constants.js'
import routes from './routes/index.js'
import { extractRequestForLogging } from './utils.js'
// Pseudo package declared only for this module
import pkg from '#package.json' with { type: 'json' }

export const build = (opts: FastifyServerOptions = {}): FastifyInstance => {
const app = fastify({ disableRequestLogging: true, requestIdHeader: PG_META_REQ_HEADER, ...opts })
const app = fastify({
disableRequestLogging: true,
requestIdHeader: PG_META_REQ_HEADER,
bodyLimit: MAX_BODY_LIMIT,
...opts,
})
Sentry.setupFastifyErrorHandler(app)

app.setErrorHandler((error, request, reply) => {
Expand Down
5 changes: 5 additions & 0 deletions src/server/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ export const PG_META_MAX_RESULT_SIZE = process.env.PG_META_MAX_RESULT_SIZE_MB
parseInt(process.env.PG_META_MAX_RESULT_SIZE_MB, 10) * 1024 * 1024
: 2 * 1024 * 1024 * 1024 // default to 2GB max query size result

export const MAX_BODY_LIMIT = process.env.PG_META_MAX_BODY_LIMIT_MB
? // Fastify server max body size allowed, is in bytes, convert from MB to Bytes
parseInt(process.env.PG_META_MAX_BODY_LIMIT_MB, 10) * 1024 * 1024
: 3 * 1024 * 1024

export const DEFAULT_POOL_CONFIG: PoolConfig = {
max: 1,
connectionTimeoutMillis: PG_CONN_TIMEOUT_SECS * 1000,
Expand Down