Minimal structure for the web server.

This commit is contained in:
Tom Alexander
2023-08-17 03:21:43 -04:00
parent cfa6e7e5ba
commit 0331c06875
4 changed files with 194 additions and 16 deletions

View File

@@ -1,3 +1,24 @@
fn main() {
println!("Hello, world!");
use axum::{http::StatusCode, routing::post, Json, Router};
use serde::Serialize;
use tower_http::services::{ServeDir, ServeFile};
#[tokio::main]
async fn main() {
let serve_dir = ServeDir::new("static").not_found_service(ServeFile::new("static/index.html"));
let app = Router::new()
.route("/parse", post(parse_org_mode))
.fallback_service(serve_dir);
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
async fn parse_org_mode(body: String) -> (StatusCode, Json<OwnerTree>) {
let ret = OwnerTree { input_source: body };
(StatusCode::OK, Json(ret))
}
#[derive(Serialize)]
struct OwnerTree {
input_source: String,
}