puppy/bin/server/src/main.rs

18 lines
632 B
Rust
Raw Normal View History

2024-04-27 09:32:00 +02:00
use axum::{extract::Path, routing::get, Json, Router};
use puppy::{get_local_ap_object, model::schema, Key, Store};
2024-04-16 20:57:07 +02:00
#[tokio::main]
async fn main() {
2024-04-27 09:32:00 +02:00
let db = Store::open(".state", schema()).unwrap();
let app = Router::new().route(
"/o/:ulid",
get(|Path(raw_object_id): Path<String>| async move {
let object_id = raw_object_id.parse::<Key>().unwrap();
let obj = get_local_ap_object(&db, object_id).unwrap().to_json_ld();
Json(obj)
}),
);
2024-04-16 20:57:07 +02:00
let sock = tokio::net::TcpListener::bind("0.0.0.0:1312").await.unwrap();
axum::serve(sock, app).await.unwrap();
}