summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorFxQnLr <[email protected]>2023-10-15 17:51:08 +0200
committerGitHub <[email protected]>2023-10-15 17:51:08 +0200
commite0be33fc23d210dbd630a1bed2fe0ecb2ea6ce0b (patch)
tree4d7a2e553c0ea67f7aa3c63d788d76d714479fd1 /src/main.rs
parentb0e8aabfb9ea0f4c40a2aa330dd59f07b6c91216 (diff)
parentabd4fbbf0ebd0385f68507eb20f9385db1b96793 (diff)
downloadwebol-e0be33fc23d210dbd630a1bed2fe0ecb2ea6ce0b.tar
webol-e0be33fc23d210dbd630a1bed2fe0ecb2ea6ce0b.tar.gz
webol-e0be33fc23d210dbd630a1bed2fe0ecb2ea6ce0b.zip
Merge pull request #2 from FxQnLr/test
Get working actions and build into main
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs
index bb37dc2..b7306ea 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,6 +7,7 @@ use sqlx::postgres::PgPoolOptions;
7use time::util::local_offset; 7use time::util::local_offset;
8use tracing::{debug, info, level_filters::LevelFilter}; 8use tracing::{debug, info, level_filters::LevelFilter};
9use tracing_subscriber::{EnvFilter, fmt::{self, time::LocalTime}, prelude::*}; 9use tracing_subscriber::{EnvFilter, fmt::{self, time::LocalTime}, prelude::*};
10use crate::config::SETTINGS;
10use crate::routes::device::{get_device, post_device, put_device}; 11use crate::routes::device::{get_device, post_device, put_device};
11use crate::routes::start::start; 12use crate::routes::start::start;
12 13
@@ -37,13 +38,12 @@ async fn main() {
37 38
38 let version = env!("CARGO_PKG_VERSION"); 39 let version = env!("CARGO_PKG_VERSION");
39 40
40 info!("starting webol v{}", version); 41 info!("start webol v{}", version);
41 42
42 let db = init_db_pool().await; 43 let db = init_db_pool().await;
43 44
44 let shared_state = Arc::new(AppState { db }); 45 let shared_state = Arc::new(AppState { db });
45 46
46 // build our application with a single route
47 let app = Router::new() 47 let app = Router::new()
48 .route("/start", post(start)) 48 .route("/start", post(start))
49 .route("/device", get(get_device)) 49 .route("/device", get(get_device))
@@ -51,8 +51,9 @@ async fn main() {
51 .route("/device", post(post_device)) 51 .route("/device", post(post_device))
52 .with_state(shared_state); 52 .with_state(shared_state);
53 53
54 // run it with hyper on localhost:3000 54 let addr = SETTINGS.get_string("serveraddr").unwrap_or("0.0.0.0:7229".to_string());
55 axum::Server::bind(&"0.0.0.0:3000".parse().unwrap()) 55 info!("start server on {}", addr);
56 axum::Server::bind(&addr.parse().unwrap())
56 .serve(app.into_make_service()) 57 .serve(app.into_make_service())
57 .await 58 .await
58 .unwrap(); 59 .unwrap();
@@ -63,9 +64,13 @@ pub struct AppState {
63} 64}
64 65
65async fn init_db_pool() -> PgPool { 66async fn init_db_pool() -> PgPool {
67 #[cfg(not(debug_assertions))]
68 let db_url = SETTINGS.get_string("database.url").unwrap();
69
70 #[cfg(debug_assertions)]
66 let db_url = env::var("DATABASE_URL").unwrap(); 71 let db_url = env::var("DATABASE_URL").unwrap();
67 72
68 debug!("attempting to connect dbPool to '{}'", db_url); 73 debug!("attempt to connect dbPool to '{}'", db_url);
69 74
70 let pool = PgPoolOptions::new() 75 let pool = PgPoolOptions::new()
71 .max_connections(5) 76 .max_connections(5)
@@ -76,4 +81,4 @@ async fn init_db_pool() -> PgPool {
76 info!("dbPool successfully connected to '{}'", db_url); 81 info!("dbPool successfully connected to '{}'", db_url);
77 82
78 pool 83 pool
79} \ No newline at end of file 84}