Skip to content

Commit a72f3b4

Browse files
committed
[FEATURE] CORS fixed:
- DTOQueryPagination defaults included.
1 parent c079a3c commit a72f3b4

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

Cargo.lock

Lines changed: 18 additions & 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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ edition = "2021"
88
[dependencies]
99
tokio = { version = "1", features = ["full"] }
1010
axum = {version = "0.7.3", features = ["tokio"]}
11+
tower-http = { version = "0.5.2", features = ["cors"] }
1112
async-trait = "0.1.80"
1213
serde = { version = "1.0", features = ["derive"] }
1314
serde_json = "1.0"

src/infrastructure/dto/dto_query_pagination.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@ use serde::Deserialize;
22

33
#[derive(Debug, Deserialize)]
44
pub struct DTOQueryPagination {
5+
#[serde(default = "default_offset")]
56
pub offset: usize,
7+
#[serde(default = "default_limit")]
68
pub limit: usize,
9+
}
10+
11+
fn default_offset() -> usize {
12+
0
13+
}
14+
15+
fn default_limit() -> usize {
16+
10
17+
}
18+
19+
impl DTOQueryPagination {
20+
21+
pub fn new(offset: usize, limit: usize) -> DTOQueryPagination {
22+
DTOQueryPagination {
23+
offset, limit
24+
}
25+
}
26+
727
}

src/main.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
use std::net::SocketAddr;
22

3+
use tower_http::cors::CorsLayer;
4+
35
use axum::Router;
4-
use rust_db_manager_api::infrastructure::controller::Controller;
6+
use rust_db_manager_api::infrastructure::{controller::Controller, dto::dto_query_pagination::DTOQueryPagination, pagination::Pagination};
57
use rust_db_manager_core::commons::configuration::configuration::Configuration;
68

79
#[tokio::main]
810
async fn main() {
911
let _ = Configuration::initialize();
1012

1113
let router = Router::new();
12-
let app = Controller::route(router).into_make_service_with_connect_info::<SocketAddr>();
14+
let app = Controller::route(router)
15+
.layer(CorsLayer::permissive())
16+
.into_make_service_with_connect_info::<SocketAddr>();
1317

1418
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
1519
axum::serve(listener, app).await.unwrap();

0 commit comments

Comments
 (0)