diff --git a/services/blob/src/http/mod.rs b/services/blob/src/http/mod.rs new file mode 100644 index 000000000..29667cb5c --- /dev/null +++ b/services/blob/src/http/mod.rs @@ -0,0 +1,33 @@ +use crate::config::CONFIG; +use crate::database::DatabaseClient; +use crate::s3::S3Client; + +use actix_web::{web, App, HttpServer}; +use anyhow::Result; +use tracing::info; + +async fn hello_handler() -> impl actix_web::Responder { + "Hello, world!" +} + +// disable unused warning for now +#[allow(unused)] +pub async fn run_http_server( + db_client: DatabaseClient, + s3_client: S3Client, +) -> Result<()> { + info!( + "Starting HTTP server listening at port {}", + CONFIG.http_port + ); + HttpServer::new(move || { + App::new() + .wrap(tracing_actix_web::TracingLogger::default()) + .service(web::resource("/hello").route(web::get().to(hello_handler))) + }) + .bind(("0.0.0.0", CONFIG.http_port))? + .run() + .await?; + + Ok(()) +} diff --git a/services/blob/src/main.rs b/services/blob/src/main.rs index b8570c9c0..276723fa8 100644 --- a/services/blob/src/main.rs +++ b/services/blob/src/main.rs @@ -1,32 +1,36 @@ pub mod config; pub mod constants; pub mod database; pub mod grpc; +pub mod http; pub mod s3; pub mod tools; use anyhow::Result; use tracing_subscriber::filter::{EnvFilter, LevelFilter}; fn configure_logging() -> Result<()> { let filter = EnvFilter::builder() .with_default_directive(LevelFilter::INFO.into()) .with_env_var(constants::LOG_LEVEL_ENV_VAR) .from_env_lossy(); let subscriber = tracing_subscriber::fmt().with_env_filter(filter).finish(); tracing::subscriber::set_global_default(subscriber)?; Ok(()) } #[tokio::main] async fn main() -> Result<()> { configure_logging()?; config::parse_cmdline_args()?; let aws_config = config::load_aws_config().await; let db = database::DatabaseClient::new(&aws_config); let s3 = s3::S3Client::new(&aws_config); - crate::grpc::run_grpc_server(db, s3).await + tokio::select! { + http_result = crate::http::run_http_server(db.clone(), s3.clone()) => http_result, + grpc_result = crate::grpc::run_grpc_server(db, s3) => grpc_result, + } }