Skip to content

Commit

Permalink
working
Browse files Browse the repository at this point in the history
  • Loading branch information
seddonm1 committed Aug 1, 2024
1 parent 26579c9 commit ea3d8fe
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 43 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ nugine-rust-utils = "0.3.1"
numeric_cast = "0.2.1"
path-absolutize = "3.1.1"
rusqlite = { version = "0.32.1", features = ["time", "uuid", "bundled"] }
# s3s = { path = "vendor/s3s" }
s3s = { git = "https://github.com/Nugine/s3s.git" }
s3s = { git = "https://github.com/seddonm1/s3s", branch = "feat/tower-service", features = [
"tower",
] }
serde = { version = "1.0.204", features = ["derive"] }
serde_json = "1.0.121"
serde_yaml = "0.9.34+deprecated"
serde_yaml = "0.9.34"
thiserror = "1.0.63"
time = "0.3.36"
tokio = { version = "1.39.2", features = ["fs", "io-util"] }
Expand All @@ -61,13 +62,12 @@ transform-stream = "0.3.0"
uuid = { version = "1.10.0", features = ["v4"] }

[dev-dependencies]
s3s-aws = { git = "https://github.com/seddonm1/s3s", branch = "feat/tower-service" }
anyhow = { version = "1.0.86", features = ["backtrace"] }
aws-config = { version = "1.5.4", default-features = false }
aws-credential-types = { version = "1.2.0", features = ["test-util"] }
aws-sdk-s3 = { version = "1.42.0", features = ["behavior-version-latest"] }
once_cell = "1.19.0"
# s3s-aws = { path = "vendor/s3s-aws" }
s3s-aws = { git = "https://github.com/Nugine/s3s.git" }
tokio = { version = "1.39.2", features = ["full"] }
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "time"] }

Expand Down
66 changes: 30 additions & 36 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,37 +167,6 @@ async fn main() -> Result<()> {
s3.build().into_shared()
};

// Run server

// let svc = TowerToHyperService::new(
// tower::ServiceBuilder::new()
// .layer(CorsLayer::very_permissive())
// // .layer(ConcurrencyLimitLayer::new(config.concurrency_limit.into()))
// .service(svc),
// );

// let svc = tower::ServiceBuilder::new()
// .layer(CorsLayer::very_permissive())
// // .layer(ConcurrencyLimitLayer::new(config.concurrency_limit.into()))
// .service(svc);
// let svc = TowerToHyperService::new(svc);

// Add CorsLayer if defined
// let service = if config.permissive_cors {
// Shared::new(TowerToHyperService::new(
// ServiceBuilder::new()
// .layer(CorsLayer::very_permissive())
// .layer(ConcurrencyLimitLayer::new(config.concurrency_limit.into()))
// .service(service.into_shared()),
// ))
// } else {
// TowerToHyperService::new(Shared::new(
// ServiceBuilder::new()
// .layer(ConcurrencyLimitLayer::new(config.concurrency_limit.into()))
// .service(service.into_shared()),
// ))
// };

// Parse addr
let addr = SocketAddr::new(config.host, config.port);
let listener = TcpListener::bind(addr).await?;
Expand Down Expand Up @@ -225,11 +194,36 @@ async fn main() -> Result<()> {
};

let io = TokioIo::new(stream);
let conn = http_server.serve_connection(io, svc.clone());
let conn = graceful.watch(conn.into_owned());
tokio::spawn(async move {
let _ = conn.await;
});

// Add CorsLayer if defined
if config.permissive_cors {
let conn = http_server.serve_connection(
io,
TowerToHyperService::new(
tower::ServiceBuilder::new()
.layer(CorsLayer::very_permissive())
.layer(ConcurrencyLimitLayer::new(config.concurrency_limit.into()))
.service(svc.clone()),
),
);
let conn = graceful.watch(conn.into_owned());
tokio::spawn(async move {
let _ = conn.await;
});
} else {
let conn = http_server.serve_connection(
io,
TowerToHyperService::new(
tower::ServiceBuilder::new()
.layer(ConcurrencyLimitLayer::new(config.concurrency_limit.into()))
.service(svc.clone()),
),
);
let conn = graceful.watch(conn.into_owned());
tokio::spawn(async move {
let _ = conn.await;
});
};
}

tokio::select! {
Expand Down

0 comments on commit ea3d8fe

Please sign in to comment.