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
19
crates/sb-api/Cargo.toml
Normal file
19
crates/sb-api/Cargo.toml
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
[package]
|
||||
name = "sb-api"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
axum = { version = "0.8", features = ["ws", "macros"] }
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
tower = "0.5"
|
||||
tower-http = { version = "0.6", features = ["cors", "trace", "compression-gzip"] }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||
sb-core = { path = "../sb-core" }
|
||||
sb-db = { path = "../sb-db" }
|
||||
sb-auth = { path = "../sb-auth" }
|
||||
sb-shared = { path = "../sb-shared" }
|
||||
sb-common = { path = "/home/jan/Development/skara-brae/skara-brae-common/rust" }
|
||||
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;
|
||||
11
crates/sb-auth/Cargo.toml
Normal file
11
crates/sb-auth/Cargo.toml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
[package]
|
||||
name = "sb-auth"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
jsonwebtoken = "9"
|
||||
argon2 = "0.5"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
sb-shared = { path = "../sb-shared" }
|
||||
0
crates/sb-auth/src/hash.rs
Normal file
0
crates/sb-auth/src/hash.rs
Normal file
0
crates/sb-auth/src/jwt.rs
Normal file
0
crates/sb-auth/src/jwt.rs
Normal file
3
crates/sb-auth/src/lib.rs
Normal file
3
crates/sb-auth/src/lib.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
pub mod jwt;
|
||||
pub mod hash;
|
||||
pub mod session;
|
||||
0
crates/sb-auth/src/session.rs
Normal file
0
crates/sb-auth/src/session.rs
Normal file
13
crates/sb-core/Cargo.toml
Normal file
13
crates/sb-core/Cargo.toml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
[package]
|
||||
name = "sb-core"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
rand = "0.9"
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
thiserror = "2"
|
||||
sb-shared = { path = "../sb-shared" }
|
||||
sb-common = { path = "/home/jan/Development/skara-brae/skara-brae-common/rust" }
|
||||
1
crates/sb-core/src/adventure/mod.rs
Normal file
1
crates/sb-core/src/adventure/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
|
||||
1
crates/sb-core/src/blessings/mod.rs
Normal file
1
crates/sb-core/src/blessings/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
|
||||
1
crates/sb-core/src/character/mod.rs
Normal file
1
crates/sb-core/src/character/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
|
||||
1
crates/sb-core/src/combat/mod.rs
Normal file
1
crates/sb-core/src/combat/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
|
||||
1
crates/sb-core/src/crafting/mod.rs
Normal file
1
crates/sb-core/src/crafting/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
|
||||
1
crates/sb-core/src/economy/mod.rs
Normal file
1
crates/sb-core/src/economy/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
|
||||
1
crates/sb-core/src/guild/mod.rs
Normal file
1
crates/sb-core/src/guild/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
|
||||
13
crates/sb-core/src/items.rs
Normal file
13
crates/sb-core/src/items.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
pub mod mod;
|
||||
|
||||
use sb_common::PROJECT_NAME;
|
||||
|
||||
const WEAPONS: &str = include_str!("../../../../skara-brae-common/data/items/weapons.json");
|
||||
|
||||
pub fn game_name() -> &'static str {
|
||||
PROJECT_NAME
|
||||
}
|
||||
|
||||
pub fn load_weapons() -> Vec<serde_json::Value> {
|
||||
serde_json::from_str(WEAPONS).expect("failed to parse weapons data")
|
||||
}
|
||||
14
crates/sb-core/src/lib.rs
Normal file
14
crates/sb-core/src/lib.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#![allow(dead_code)]
|
||||
|
||||
pub mod character;
|
||||
pub mod combat;
|
||||
pub mod adventure;
|
||||
pub mod economy;
|
||||
pub mod guild;
|
||||
pub mod crafting;
|
||||
pub mod pets;
|
||||
pub mod blessings;
|
||||
pub mod workers;
|
||||
pub mod slayer;
|
||||
pub mod world;
|
||||
pub mod rules;
|
||||
1
crates/sb-core/src/pets/mod.rs
Normal file
1
crates/sb-core/src/pets/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
|
||||
1
crates/sb-core/src/rules/mod.rs
Normal file
1
crates/sb-core/src/rules/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
|
||||
1
crates/sb-core/src/slayer/mod.rs
Normal file
1
crates/sb-core/src/slayer/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
|
||||
1
crates/sb-core/src/workers/mod.rs
Normal file
1
crates/sb-core/src/workers/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
|
||||
1
crates/sb-core/src/world/mod.rs
Normal file
1
crates/sb-core/src/world/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
|
||||
9
crates/sb-db/Cargo.toml
Normal file
9
crates/sb-db/Cargo.toml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "sb-db"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
sqlx = { version = "0.8", features = ["runtime-tokio", "postgres", "chrono", "uuid", "migrate"] }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
sb-shared = { path = "../sb-shared" }
|
||||
4
crates/sb-db/src/lib.rs
Normal file
4
crates/sb-db/src/lib.rs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#![allow(dead_code)]
|
||||
|
||||
pub mod models;
|
||||
pub mod queries;
|
||||
0
crates/sb-db/src/migrations/mod.rs
Normal file
0
crates/sb-db/src/migrations/mod.rs
Normal file
0
crates/sb-db/src/models/mod.rs
Normal file
0
crates/sb-db/src/models/mod.rs
Normal file
0
crates/sb-db/src/queries/mod.rs
Normal file
0
crates/sb-db/src/queries/mod.rs
Normal file
9
crates/sb-shared/Cargo.toml
Normal file
9
crates/sb-shared/Cargo.toml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "sb-shared"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
thiserror = "2"
|
||||
15
crates/sb-shared/src/errors.rs
Normal file
15
crates/sb-shared/src/errors.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct AppError {
|
||||
pub code: String,
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for AppError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}: {}", self.code, self.message)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for AppError {}
|
||||
3
crates/sb-shared/src/lib.rs
Normal file
3
crates/sb-shared/src/lib.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
pub mod errors;
|
||||
|
||||
pub use errors::AppError;
|
||||
Loading…
Add table
Add a link
Reference in a new issue