add session_id + uuid parsing
This commit is contained in:
19
src/main.rs
19
src/main.rs
@@ -1,16 +1,33 @@
|
||||
use axum::{routing::get, Router};
|
||||
use axum_extra::extract::{cookie::Cookie, CookieJar};
|
||||
use tower_http::services::ServeDir;
|
||||
use uuid::Uuid;
|
||||
|
||||
mod collector;
|
||||
mod index;
|
||||
mod page;
|
||||
|
||||
fn device_id(cookies: CookieJar) -> (CookieJar, String) {
|
||||
let mut cookies = cookies;
|
||||
if cookies.get("device_id").is_none() {
|
||||
let id = Uuid::new_v4().to_string();
|
||||
cookies = cookies.add(Cookie::new("device_id", id))
|
||||
}
|
||||
|
||||
let id = cookies
|
||||
.get("device_id")
|
||||
.expect("can't happen, as we checked above")
|
||||
.to_string();
|
||||
|
||||
(cookies, id)
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
// build our application with a single route
|
||||
let app = Router::new()
|
||||
.route("/", get(index::index))
|
||||
.route("/cam", get(collector::collector))
|
||||
.nest("/cam", collector::routes())
|
||||
.fallback_service(ServeDir::new("./static/serve"));
|
||||
|
||||
// run our app with hyper, listening globally on port 3000
|
||||
|
Reference in New Issue
Block a user