Skip to content

Commit 48cb72f

Browse files
committed
Add configurable JSON body size limit via MAX_BODY_SIZE_MB
- Add max_body_size_mb field to ServerConfig (default: 10 MB) - Read MAX_BODY_SIZE_MB environment variable - Configure Actix-web JsonConfig with the limit - Fixes upload issues with large JSON payloads (e.g., worker deployments) - Bump version to 0.1.4
1 parent edc52a6 commit 48cb72f

4 files changed

Lines changed: 19 additions & 4 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "postgate"
3-
version = "0.1.3"
3+
version = "0.1.4"
44
edition = "2024"
55
default-run = "postgate"
66
description = "Secure HTTP proxy for PostgreSQL with SQL validation and multi-tenant support"

src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ pub struct Config {
1111
pub struct ServerConfig {
1212
pub host: String,
1313
pub port: u16,
14+
pub max_body_size_mb: usize,
1415
}
1516

1617
impl Default for ServerConfig {
1718
fn default() -> Self {
1819
Self {
1920
host: "127.0.0.1".to_string(),
2021
port: 3000,
22+
max_body_size_mb: 10,
2123
}
2224
}
2325
}

src/main.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ fn load_config() -> Config {
6161
.ok()
6262
.and_then(|p| p.parse().ok())
6363
.unwrap_or(3000);
64+
let max_body_size_mb = env::var("MAX_BODY_SIZE_MB")
65+
.ok()
66+
.and_then(|s| s.parse().ok())
67+
.unwrap_or(10);
6468

6569
let database_url = match std::env::var("DATABASE_URL") {
6670
Ok(url) => url,
@@ -79,7 +83,11 @@ fn load_config() -> Config {
7983
};
8084

8185
Config {
82-
server: ServerConfig { host, port },
86+
server: ServerConfig {
87+
host,
88+
port,
89+
max_body_size_mb,
90+
},
8391
database_url,
8492
}
8593
}
@@ -255,11 +263,16 @@ async fn main() -> std::io::Result<()> {
255263
// Create store (uses the shared pool)
256264
let store = Store::new(executor_pool.shared_pool().clone());
257265

258-
let state = web::Data::new(AppState::new(config, executor_pool, store));
266+
let state = web::Data::new(AppState::new(config.clone(), executor_pool, store));
267+
268+
// Configure JSON payload size limit
269+
let json_config = web::JsonConfig::default()
270+
.limit(config.server.max_body_size_mb * 1024 * 1024);
259271

260272
HttpServer::new(move || {
261273
App::new()
262274
.app_data(state.clone())
275+
.app_data(json_config.clone())
263276
.configure(configure_routes)
264277
})
265278
.bind(&bind_addr)?

0 commit comments

Comments
 (0)