aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorfx <[email protected]>2023-10-09 16:06:08 +0200
committerfx <[email protected]>2023-10-09 16:06:08 +0200
commit732c487d3dab4af9fc561527591d3d56299e39f2 (patch)
tree8c26464761f0c879a0aa7517e236af72cf87c6b2 /src/main.rs
parentbc5f721de8996b48550b5069f5592caf2968e822 (diff)
downloadwebol-732c487d3dab4af9fc561527591d3d56299e39f2.tar
webol-732c487d3dab4af9fc561527591d3d56299e39f2.tar.gz
webol-732c487d3dab4af9fc561527591d3d56299e39f2.zip
added db for devices
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index 0fe170d..761e925 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,8 @@
1use std::sync::Arc;
1use axum::{Router, routing::post}; 2use axum::{Router, routing::post};
3use sqlx::SqlitePool;
2use time::util::local_offset; 4use time::util::local_offset;
3use tracing::{info, level_filters::LevelFilter}; 5use tracing::{debug, info, level_filters::LevelFilter};
4use tracing_subscriber::{EnvFilter, fmt::{self, time::LocalTime}, prelude::*}; 6use tracing_subscriber::{EnvFilter, fmt::{self, time::LocalTime}, prelude::*};
5use crate::routes::start::start; 7use crate::routes::start::start;
6 8
@@ -8,6 +10,7 @@ mod auth;
8mod config; 10mod config;
9mod routes; 11mod routes;
10mod wol; 12mod wol;
13mod db;
11 14
12#[tokio::main] 15#[tokio::main]
13async fn main() { 16async fn main() {
@@ -27,13 +30,21 @@ async fn main() {
27 ) 30 )
28 .init(); 31 .init();
29 32
33 debug!("connecting to db");
34 let db = SqlitePool::connect("sqlite:devices.sqlite").await.unwrap();
35 sqlx::migrate!().run(&db).await.unwrap();
36 info!("connected to db");
37
30 let version = env!("CARGO_PKG_VERSION"); 38 let version = env!("CARGO_PKG_VERSION");
31 39
32 info!("Starting webol v{}", version); 40 info!("starting webol v{}", version);
41
42 let shared_state = Arc::new(AppState { db });
33 43
34 // build our application with a single route 44 // build our application with a single route
35 let app = Router::new() 45 let app = Router::new()
36 .route("/start", post(start)); 46 .route("/start", post(start))
47 .with_state(shared_state);
37 48
38 // run it with hyper on localhost:3000 49 // run it with hyper on localhost:3000
39 axum::Server::bind(&"0.0.0.0:3000".parse().unwrap()) 50 axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
@@ -42,3 +53,6 @@ async fn main() {
42 .unwrap(); 53 .unwrap();
43} 54}
44 55
56pub struct AppState {
57 db: SqlitePool
58} \ No newline at end of file