mirror of
https://github.com/cupcakearmy/cryptgeon.git
synced 2024-12-22 08:16:28 +00:00
middleware to handle json payloads
This commit is contained in:
parent
8644a937d0
commit
ac5d52a010
13
src/main.rs
13
src/main.rs
@ -5,19 +5,28 @@ extern crate lazy_static;
|
|||||||
|
|
||||||
mod client;
|
mod client;
|
||||||
mod note;
|
mod note;
|
||||||
|
mod size;
|
||||||
mod store;
|
mod store;
|
||||||
|
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
HttpServer::new(|| {
|
return HttpServer::new(|| {
|
||||||
App::new()
|
App::new()
|
||||||
|
// .configure(|cfg: &mut web::ServiceConfig| {
|
||||||
|
// let limit_string = std::env::var("SIZE_LIMIT").unwrap_or("0.1 KiB".to_string());
|
||||||
|
// let limit = Byte::from_str(limit_string.clone()).unwrap().get_bytes() as usize;
|
||||||
|
// println!("SIZE_LIMIT: {}, {}", limit_string, limit);
|
||||||
|
// let config = web::JsonConfig::default().limit(limit);
|
||||||
|
// cfg.data(config);
|
||||||
|
// })
|
||||||
.wrap(middleware::Compress::default())
|
.wrap(middleware::Compress::default())
|
||||||
.wrap(middleware::DefaultHeaders::default())
|
.wrap(middleware::DefaultHeaders::default())
|
||||||
|
.configure(size::init)
|
||||||
.configure(note::init)
|
.configure(note::init)
|
||||||
.configure(client::init)
|
.configure(client::init)
|
||||||
.default_service(web::resource("").route(web::get().to(client::fallback_fn)))
|
.default_service(web::resource("").route(web::get().to(client::fallback_fn)))
|
||||||
})
|
})
|
||||||
.bind("0.0.0.0:5000")?
|
.bind("0.0.0.0:5000")?
|
||||||
.run()
|
.run()
|
||||||
.await
|
.await;
|
||||||
}
|
}
|
||||||
|
10
src/size.rs
Normal file
10
src/size.rs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
use actix_web::web;
|
||||||
|
use byte_unit::Byte;
|
||||||
|
|
||||||
|
pub fn init(cfg: &mut web::ServiceConfig) {
|
||||||
|
let limit_string = std::env::var("SIZE_LIMIT").unwrap_or("1 KiB".to_string());
|
||||||
|
let limit = Byte::from_str(limit_string.clone()).unwrap().get_bytes() as usize;
|
||||||
|
println!("SIZE_LIMIT: {}, {}", limit_string, limit);
|
||||||
|
let config = web::JsonConfig::default().limit(limit);
|
||||||
|
cfg.data(config);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user