diff --git a/Cargo.lock b/Cargo.lock index e739d22..fca99a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -740,7 +740,7 @@ checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" [[package]] name = "kosyncrs" -version = "1.1.1" +version = "2.0.0" dependencies = [ "axum", "serde", diff --git a/src/main.rs b/src/main.rs index 99373e6..bbf116f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,12 +39,15 @@ pub struct GetProgress { timestamp: i64, } +const VERSION: &str = env!("CARGO_PKG_VERSION"); + #[tokio::main] async fn main() { let pg_url: String = env::var("PG_URL") .ok() .and_then(|v| v.parse().ok()) .unwrap(); + let listen_port: String = env::var("PORT").ok().and_then(|v| v.parse().ok()).unwrap(); let db_pool = PgPoolOptions::new() .max_connections(64) @@ -61,10 +64,12 @@ async fn main() { .route("/syncs/progress", put(update_progress)) .route("/syncs/progress/{document}", get(get_progress)) .route("/healthcheck", get(healthcheck)) + .route("/version", get(version)) .with_state(db_pool); - // run it with hyper on localhost:3003 - let listener = tokio::net::TcpListener::bind("127.0.0.1:3003") + let mut bind_with = "127.0.0.1:".to_owned(); + bind_with += &listen_port; + let listener = tokio::net::TcpListener::bind(bind_with) .await .unwrap(); axum::serve(listener, app).await.unwrap(); @@ -74,6 +79,10 @@ async fn root() -> &'static str { "KOreader sync server" } +async fn version() -> &'static str { + VERSION +} + async fn create_user( State(db_pool): State, Json(payload): Json, diff --git a/systemd/kosyncrs.service b/systemd/kosyncrs.service index b405332..1809f9a 100644 --- a/systemd/kosyncrs.service +++ b/systemd/kosyncrs.service @@ -12,6 +12,7 @@ Group=users WorkingDirectory=/home/myuser ExecStart=/usr/local/bin/kosyncrs Environment="PG_URL=postgresql://kosync:password@localhost/kosync" +Environment="PORT=3003" Restart=always [Install]