Archived
feat: neuron-rs — Rust runtime, Engram-backed, Axon protocol
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use tracing::info;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
||||
mod auth;
|
||||
mod error;
|
||||
mod routes;
|
||||
mod state;
|
||||
|
||||
use state::AppState;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
tracing_subscriber::fmt()
|
||||
.with_env_filter(
|
||||
EnvFilter::from_default_env()
|
||||
.add_directive("neuron_api=info".parse().unwrap()),
|
||||
)
|
||||
.init();
|
||||
|
||||
let db_path_raw = std::env::var("NEURON_DB_PATH")
|
||||
.unwrap_or_else(|_| "~/.neuron/engram".to_string());
|
||||
let db_path = PathBuf::from(
|
||||
db_path_raw
|
||||
.replace('~', &std::env::var("HOME").unwrap_or_else(|_| ".".to_string())),
|
||||
);
|
||||
std::fs::create_dir_all(&db_path).expect("failed to create db directory");
|
||||
|
||||
let api_key = std::env::var("NEURON_API_KEY").unwrap_or_else(|_| "neuron-dev".to_string());
|
||||
let bind = std::env::var("NEURON_BIND").unwrap_or_else(|_| "0.0.0.0:7770".to_string());
|
||||
|
||||
info!("opening engram db at {}", db_path.display());
|
||||
let state = AppState::new(&db_path, api_key).expect("failed to initialize app state");
|
||||
let state = Arc::new(state);
|
||||
|
||||
let app = routes::build_router(state);
|
||||
|
||||
let listener = tokio::net::TcpListener::bind(&bind)
|
||||
.await
|
||||
.expect("failed to bind");
|
||||
info!("neuron-api listening on {}", bind);
|
||||
axum::serve(listener, app).await.expect("server error");
|
||||
}
|
||||
Reference in New Issue
Block a user