Initial scaffold: Rust server workspace (sb-api, sb-core, sb-db, sb-auth, sb-shared) + sb-common dependency + systemd
This commit is contained in:
commit
7a75a523f0
39 changed files with 183 additions and 0 deletions
34
crates/sb-api/src/main.rs
Normal file
34
crates/sb-api/src/main.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#![allow(dead_code)]
|
||||
|
||||
use axum::routing::get;
|
||||
use axum::Router;
|
||||
use tracing_subscriber::layer::SubscriberExt;
|
||||
use tracing_subscriber::util::SubscriberInitExt;
|
||||
|
||||
pub mod routes;
|
||||
pub mod ws;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
tracing_subscriber::registry()
|
||||
.with(tracing_subscriber::fmt::layer().pretty())
|
||||
.with(tracing_subscriber::EnvFilter::new(
|
||||
std::env::var("RUST_LOG").unwrap_or_else(|_| "info".into()),
|
||||
))
|
||||
.init();
|
||||
|
||||
let app = Router::new()
|
||||
.route("/health", get(health))
|
||||
.merge(routes::build());
|
||||
|
||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:8080")
|
||||
.await
|
||||
.expect("failed to bind");
|
||||
|
||||
tracing::info!("listening on {:?}", listener.local_addr());
|
||||
axum::serve(listener, app).await.expect("server error");
|
||||
}
|
||||
|
||||
async fn health() -> &'static str {
|
||||
"ok"
|
||||
}
|
||||
0
crates/sb-api/src/middleware/auth.rs
Normal file
0
crates/sb-api/src/middleware/auth.rs
Normal file
2
crates/sb-api/src/middleware/mod.rs
Normal file
2
crates/sb-api/src/middleware/mod.rs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
pub mod auth;
|
||||
pub mod rate_limit;
|
||||
0
crates/sb-api/src/middleware/rate_limit.rs
Normal file
0
crates/sb-api/src/middleware/rate_limit.rs
Normal file
5
crates/sb-api/src/routes/mod.rs
Normal file
5
crates/sb-api/src/routes/mod.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
use axum::{routing::get, Router};
|
||||
|
||||
pub fn build() -> Router {
|
||||
Router::new().route("/", get(|| async { "skara-brae api" }))
|
||||
}
|
||||
0
crates/sb-api/src/ws/channels.rs
Normal file
0
crates/sb-api/src/ws/channels.rs
Normal file
0
crates/sb-api/src/ws/handler.rs
Normal file
0
crates/sb-api/src/ws/handler.rs
Normal file
2
crates/sb-api/src/ws/mod.rs
Normal file
2
crates/sb-api/src/ws/mod.rs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
pub mod handler;
|
||||
pub mod channels;
|
||||
Loading…
Add table
Add a link
Reference in a new issue