project: add shuttle build dependencies and shuttle main
This commit is contained in:
parent
11531b7d50
commit
7588c01f92
4 changed files with 825 additions and 256 deletions
1018
Cargo.lock
generated
1018
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
18
Cargo.toml
18
Cargo.toml
|
|
@ -3,17 +3,17 @@ name = "caesar_test"
|
|||
version = "0.0.1"
|
||||
edition = "2021"
|
||||
build = "src/build.rs"
|
||||
authors = ["Manuel Keidel", "Patryk Hegenberg", "Krzysztof Stankiewicz"]
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[[bin]]
|
||||
name = "caesar"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
futures-util = "0.3"
|
||||
tungstenite = "0.20.1"
|
||||
tungstenite = "0.21.0"
|
||||
tokio = { version = "1.28.1", features = ["full"] }
|
||||
tokio-tungstenite = { version = "0.20.1" }
|
||||
tokio-tungstenite = { version = "0.21.0" }
|
||||
serde_json = { version = "1.0" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
uuid = { version = "1.3.2", features = ["v4"] }
|
||||
|
|
@ -22,16 +22,16 @@ tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
|||
dotenv = { version = "0.15.0", features = ["clap", "cli"] }
|
||||
clap = { version = "4.5.4", features = ["derive"] }
|
||||
flume = { git = "https://github.com/zesterer/flume", rev = "80d19c49" }
|
||||
prost = "0.11.9"
|
||||
prost-types = "0.11.9"
|
||||
base64 = "0.21.2"
|
||||
prost = "0.12.4"
|
||||
prost-types = "0.12.4"
|
||||
base64 = "0.22.0"
|
||||
url = "2.4.0"
|
||||
p256 = { version = "0.13.2", features = ["ecdh"] }
|
||||
hmac = "0.12.1"
|
||||
sha2 = "0.10.7"
|
||||
rand = { version = "0.8.5", features = ["getrandom"] }
|
||||
aes-gcm = "0.10.3"
|
||||
sanitize-filename = "0.4.0"
|
||||
sanitize-filename = "0.5.0"
|
||||
qr2term = "0.3.1"
|
||||
axum = { version = "0.7.5", features = ["ws"] }
|
||||
tower-http = { version = "0.5.2", features = ["fs", "trace"] }
|
||||
|
|
@ -40,6 +40,8 @@ local-ip-address = "0.6.1"
|
|||
axum-extra = { version = "0.9.3", features = ["typed-header"] }
|
||||
headers = "0.4"
|
||||
tower = { version = "0.4", features = ["util"] }
|
||||
shuttle-axum = { version = "0.44.0", optional = true }
|
||||
shuttle-runtime = { version = "0.44.0", optional = true }
|
||||
|
||||
[build-dependencies]
|
||||
prost-build = "0.5"
|
||||
prost-build = "0.12.4"
|
||||
|
|
|
|||
29
src/main.rs
29
src/main.rs
|
|
@ -1,6 +1,9 @@
|
|||
use crate::cli::args::Args;
|
||||
use dotenv::dotenv;
|
||||
#[cfg(feature = "shuttle")]
|
||||
use shuttle_axum::ShuttleAxum;
|
||||
use tracing::error;
|
||||
#[cfg(not(feature = "shuttle"))]
|
||||
use tracing_subscriber::filter::EnvFilter;
|
||||
|
||||
pub mod cli;
|
||||
|
|
@ -9,6 +12,7 @@ pub mod relay;
|
|||
pub mod sender;
|
||||
pub mod shared;
|
||||
|
||||
#[cfg(not(feature = "shuttle"))]
|
||||
#[tokio::main]
|
||||
// This is the entrypoint of caesar.
|
||||
// The #[tokio::main] attribute is required for any async code, and it
|
||||
|
|
@ -35,3 +39,28 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
|||
// Return an Ok result, which just means that our program exited successfully.
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "shuttle")]
|
||||
#[shuttle_runtime::main]
|
||||
async fn main() -> ShuttleAxum {
|
||||
let app_host = env::var("APP_HOST").unwrap_or("0.0.0.0".to_string());
|
||||
let app_port = env::var("APP_PORT").unwrap_or("8000".to_string());
|
||||
|
||||
// Log information about the server's configuration.
|
||||
debug!("Server configured to accept connections on host {app_host}...",);
|
||||
debug!("Server configured to listen connections on port {app_port}...",);
|
||||
|
||||
// Create a new server data structure.
|
||||
let server = server::Server::new();
|
||||
|
||||
// Set up the application routes.
|
||||
let app = Router::new()
|
||||
.route("/ws", get(ws_handler))
|
||||
.with_state(server)
|
||||
.layer(SecureClientIpSource::ConnectInfo.into_extension())
|
||||
.layer(
|
||||
TraceLayer::new_for_http()
|
||||
.make_span_with(DefaultMakeSpan::default().include_headers(true)),
|
||||
);
|
||||
Ok(app.into())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,18 +72,10 @@ pub async fn start_ws(port: Option<&i32>, listen_addr: Option<&String>) {
|
|||
Some(port) => port.to_string(),
|
||||
None => env::var("APP_PORT").unwrap_or("8000".to_string()),
|
||||
};
|
||||
let app_domain = env::var("APP_DOMAIN").unwrap_or("".to_string());
|
||||
|
||||
// Log information about the server's configuration.
|
||||
debug!(
|
||||
"Server configured to accept connections on host {app_host}...",
|
||||
);
|
||||
debug!(
|
||||
"Server configured to listen connections on port {app_port}...",
|
||||
);
|
||||
debug!(
|
||||
"Server configured to listen connections on port {app_domain}...",
|
||||
);
|
||||
debug!("Server configured to accept connections on host {app_host}...",);
|
||||
debug!("Server configured to listen connections on port {app_port}...",);
|
||||
|
||||
// Based on the environment variable, set the logging level.
|
||||
match app_environemt.as_str() {
|
||||
|
|
@ -130,7 +122,6 @@ pub async fn start_ws(port: Option<&i32>, listen_addr: Option<&String>) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// This function is an endpoint for the WebSocket route.
|
||||
///
|
||||
/// This function is called whenever a client makes a WebSocket request to
|
||||
|
|
@ -177,7 +168,6 @@ async fn ws_handler(
|
|||
ws.on_upgrade(move |socket| handle_socket(socket, addr, shared_state))
|
||||
}
|
||||
|
||||
|
||||
/// This function is called when a new WebSocket connection is established.
|
||||
/// The function takes three arguments:
|
||||
///
|
||||
|
|
@ -233,7 +223,6 @@ async fn handle_socket(socket: WebSocket, who: SocketAddr, rooms: Arc<RwLock<ser
|
|||
client.handle_close(&rooms).await
|
||||
}
|
||||
|
||||
|
||||
/// This function sets up a signal handler for SIGINT (Ctrl+C) and SIGTERM
|
||||
/// (terminate) on Unix platforms. It does nothing on non-Unix platforms.
|
||||
///
|
||||
|
|
@ -285,4 +274,3 @@ async fn shutdown_signal() {
|
|||
_ = terminate => {},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue