Compare commits

...

3 commits

Author SHA1 Message Date
ab444e07f4 add listen port 2025-01-08 15:06:57 +01:00
3374110f38 add version info 2025-01-08 14:56:18 +01:00
d2ccc665fb 2025-01-08 14:55:59 +01:00
3 changed files with 13 additions and 3 deletions

2
Cargo.lock generated
View file

@ -740,7 +740,7 @@ checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674"
[[package]]
name = "kosyncrs"
version = "1.1.1"
version = "2.0.0"
dependencies = [
"axum",
"serde",

View file

@ -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<PgPool>,
Json(payload): Json<User>,

View file

@ -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]