Skip to content

Commit

Permalink
Increase backend payload size limit to 2MB (#1374)
Browse files Browse the repository at this point in the history
  • Loading branch information
nygrenh authored Jan 24, 2025
1 parent 6ba6ea7 commit e0dfc6b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions services/headless-lms/server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
use actix_http::{body::MessageBody, StatusCode};
use actix_web::{
error::InternalError,
web::{self, Data, ServiceConfig},
web::{self, Data, PayloadConfig, ServiceConfig},
HttpResponse,
};
use anyhow::Context;
Expand Down Expand Up @@ -52,7 +52,7 @@ impl ServerConfigBuilder {
}

pub async fn build(self) -> anyhow::Result<ServerConfig> {
let json_config = web::JsonConfig::default().limit(1048576).error_handler(
let json_config = web::JsonConfig::default().limit(2_097_152).error_handler(
|err, _req| -> actix_web::Error {
info!("Bad request: {}", &err);
let body = format!("{{\"title\": \"Bad Request\", \"message\": \"{}\"}}", &err);
Expand All @@ -63,6 +63,9 @@ impl ServerConfigBuilder {
);
let json_config = Data::new(json_config);

let payload_config = PayloadConfig::default().limit(2_097_152);
let payload_config = Data::new(payload_config);

let db_pool = PgPoolOptions::new()
.max_connections(15)
.min_connections(5)
Expand Down Expand Up @@ -102,13 +105,15 @@ impl ServerConfigBuilder {
app_conf,
jwt_key,
cache,
payload_config,
};
Ok(config)
}
}

#[derive(Clone)]
pub struct ServerConfig {
pub payload_config: Data<PayloadConfig>,
pub json_config: Data<web::JsonConfig>,
pub db_pool: Data<PgPool>,
pub oauth_client: Data<OAuthClient>,
Expand All @@ -132,11 +137,13 @@ pub fn configure(config: &mut ServiceConfig, server_config: ServerConfig) {
app_conf,
jwt_key,
cache,
payload_config,
} = server_config;
// turns file_store from `dyn FileStore + Send + Sync` to `dyn FileStore` to match controllers
// Not using Data::new for file_store to avoid double wrapping it in a arc
let file_store = Data::from(file_store as Arc<dyn FileStore>);
config
.app_data(payload_config)
.app_data(json_config)
.app_data(db_pool)
.app_data(oauth_client)
Expand Down

0 comments on commit e0dfc6b

Please sign in to comment.