diff options
| author | lonkaars <loek@pipeframe.xyz> | 2021-08-18 11:35:41 +0200 |
|---|---|---|
| committer | lonkaars <loek@pipeframe.xyz> | 2021-08-18 11:35:41 +0200 |
| commit | 246851e85c3ac1d62853ee7622ad86549aaf40e2 (patch) | |
| tree | 7c138e9c9102a6a5bd1dc9799dfb180415c42c24 /api/src/main.rs | |
| parent | 36a263aee35a819e90bb9430a70d0e5ba321ba63 (diff) | |
more api but brokey
Diffstat (limited to 'api/src/main.rs')
| -rw-r--r-- | api/src/main.rs | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/api/src/main.rs b/api/src/main.rs index b2e75c9..8d4f537 100644 --- a/api/src/main.rs +++ b/api/src/main.rs @@ -1,31 +1,30 @@ extern crate log; -extern crate mongodb; extern crate simple_logger; extern crate tokio; -use mongodb::{bson::doc, options::ClientOptions, Client}; +use actix_web::{web, App, HttpServer}; use simple_logger::SimpleLogger; +use std::io::Result; +use std::sync::*; -#[tokio::main] -async fn main() -> mongodb::error::Result<()> { +mod db; +mod routes; + +fn init_log() { SimpleLogger::new().init().unwrap(); log::set_max_level(log::LevelFilter::Info); +} - let mut client_options = ClientOptions::parse("mongodb://localhost:27017").await?; - - client_options.app_name = Some("pressure-api".to_string()); - - let client = Client::with_options(client_options)?; - - client - .database("admin") - .run_command(doc! {"ping": 1}, None) - .await?; - log::info!("connected to mongodb"); - - for db_name in client.list_database_names(None, None).await? { - log::info!("{}", db_name); - } - - Ok(()) +#[actix_rt::main] +async fn main() -> Result<()> { + init_log(); + let client = web::Data::new(Mutex::new(db::init())); + HttpServer::new(move || { + App::new() + .app_data(client.clone()) + .service(web::scope("/").configure(routes::export_routes)) + }) + .bind("127.0.0.1:8080")? + .run() + .await } |