From d2ccc665fb01226a95f711603ce7378b812a363e Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Wed, 8 Jan 2025 14:55:59 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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", From 3374110f389cd105a8c5c9c29b2a118b74b33c3a Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Wed, 8 Jan 2025 14:56:18 +0100 Subject: [PATCH 2/3] add version info --- src/main.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main.rs b/src/main.rs index 99373e6..dadab76 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,6 +39,8 @@ 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") @@ -61,6 +63,7 @@ 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 @@ -74,6 +77,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, From ab444e07f41476add9c3cb70f20f8ad94399050f Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Wed, 8 Jan 2025 15:06:57 +0100 Subject: [PATCH 3/3] add listen port --- src/main.rs | 6 ++++-- systemd/kosyncrs.service | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index dadab76..bbf116f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,6 +47,7 @@ async fn main() { .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) @@ -66,8 +67,9 @@ async fn main() { .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(); 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]