add sqlite db; add todos :-(; show current cameras

This commit is contained in:
2025-08-02 17:46:56 +02:00
parent 3f61f675e9
commit fe89c86004
14 changed files with 1653 additions and 31 deletions

View File

@@ -1,12 +1,19 @@
use axum::{routing::get, Router};
use axum_extra::extract::{cookie::Cookie, CookieJar};
use sqlx::{pool::PoolOptions, sqlite::SqliteConnectOptions, SqlitePool};
use std::{str::FromStr, sync::Arc};
use tower_http::services::ServeDir;
use uuid::Uuid;
mod game;
mod index;
pub(crate) mod model;
mod page;
pub(crate) enum Backend {
Sqlite(SqlitePool),
}
fn client_id(cookies: CookieJar) -> (CookieJar, String) {
let mut cookies = cookies;
if cookies.get("client_id").is_none() {
@@ -24,10 +31,17 @@ fn client_id(cookies: CookieJar) -> (CookieJar, String) {
#[tokio::main]
async fn main() {
let connection_options = SqliteConnectOptions::from_str("sqlite://db.sqlite").unwrap();
let db: SqlitePool = PoolOptions::new()
.connect_with(connection_options)
.await
.unwrap();
let app = Router::new()
.route("/", get(index::index))
.nest_service("/static", ServeDir::new("./static/serve"))
.merge(game::routes());
.merge(game::routes())
.with_state(Arc::new(Backend::Sqlite(db)));
// run our app with hyper, listening globally on port 3000
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();