mirror of
https://github.com/atuinsh/atuin.git
synced 2025-08-19 03:16:54 +02:00
Start implementing server
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -135,6 +135,7 @@ version = "14.0.1"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"atuin-common",
|
"atuin-common",
|
||||||
|
"axum",
|
||||||
"base64 0.21.0",
|
"base64 0.21.0",
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
|
@@ -64,5 +64,8 @@ semver = { workspace = true }
|
|||||||
xsalsa20poly1305 = { version = "0.9.0", optional = true }
|
xsalsa20poly1305 = { version = "0.9.0", optional = true }
|
||||||
generic-array = { version = "0.14", optional = true, features = ["serde"] }
|
generic-array = { version = "0.14", optional = true, features = ["serde"] }
|
||||||
|
|
||||||
|
# daemon
|
||||||
|
axum = "0.6.4"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tokio = { version = "1", features = ["full"] }
|
tokio = { version = "1", features = ["full"] }
|
||||||
|
8
atuin-client/src/daemon/handlers/mod.rs
Normal file
8
atuin-client/src/daemon/handlers/mod.rs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
|
pub async fn index() -> Json<IndexResponse> {
|
||||||
|
Json(IndexResponse {
|
||||||
|
version: VERSION.to_string(),
|
||||||
|
})
|
||||||
|
}
|
1
atuin-client/src/daemon/mod.rs
Normal file
1
atuin-client/src/daemon/mod.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
pub mod router;
|
44
atuin-client/src/daemon/router.rs
Normal file
44
atuin-client/src/daemon/router.rs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
use std::net::{IpAddr, SocketAddr};
|
||||||
|
|
||||||
|
use axum::{
|
||||||
|
response::IntoResponse,
|
||||||
|
routing::{get},
|
||||||
|
Router,
|
||||||
|
Server,
|
||||||
|
};
|
||||||
|
use eyre::{Result};
|
||||||
|
|
||||||
|
use crate::settings::Settings;
|
||||||
|
|
||||||
|
async fn teapot() -> impl IntoResponse {
|
||||||
|
(http::StatusCode::IM_A_TEAPOT, "☕")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn router(
|
||||||
|
settings: Settings,
|
||||||
|
) -> Router {
|
||||||
|
let routes = Router::new()
|
||||||
|
.route("/", get(handlers::index));
|
||||||
|
|
||||||
|
let path = settings.path.as_str();
|
||||||
|
if path.is_empty() {
|
||||||
|
routes
|
||||||
|
} else {
|
||||||
|
Router::new().nest(path, routes)
|
||||||
|
}
|
||||||
|
.fallback(teapot)
|
||||||
|
.with_state(AppState { database, settings })
|
||||||
|
.layer(ServiceBuilder::new().layer(TraceLayer::new_for_http()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn listen(settings: Settings, host: String, port: u16) -> Result<()> {
|
||||||
|
let host = host.parse::<IpAddr>()?;
|
||||||
|
|
||||||
|
let r = router(settings);
|
||||||
|
|
||||||
|
Server::bind(&SocketAddr::new(host, port))
|
||||||
|
.serve(r.into_make_service())
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
@@ -10,6 +10,7 @@ pub mod encryption;
|
|||||||
#[cfg(feature = "sync")]
|
#[cfg(feature = "sync")]
|
||||||
pub mod sync;
|
pub mod sync;
|
||||||
|
|
||||||
|
pub mod daemon;
|
||||||
pub mod database;
|
pub mod database;
|
||||||
pub mod history;
|
pub mod history;
|
||||||
pub mod import;
|
pub mod import;
|
||||||
|
@@ -6,7 +6,7 @@ use tracing_subscriber::FmtSubscriber;
|
|||||||
|
|
||||||
use daemonize::Daemonize;
|
use daemonize::Daemonize;
|
||||||
|
|
||||||
use atuin_client::settings::Settings;
|
use atuin_client::{daemon, settings::Settings};
|
||||||
use tracing::{error, info, Level};
|
use tracing::{error, info, Level};
|
||||||
|
|
||||||
pub fn start(settings: Settings) -> Result<()> {
|
pub fn start(settings: Settings) -> Result<()> {
|
||||||
|
Reference in New Issue
Block a user