Compare commits
3 commits
Author | SHA1 | Date | |
---|---|---|---|
e3114beb9a | |||
249c30f2da | |||
9c8b39e98f |
3 changed files with 233 additions and 272 deletions
473
Cargo.lock
generated
473
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "kosyncrs"
|
name = "kosyncrs"
|
||||||
version = "2.1.1"
|
version = "2.2.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
@ -10,4 +10,4 @@ axum = "0.8.1"
|
||||||
serde = { version = "1.0.188", features = ["derive"] }
|
serde = { version = "1.0.188", features = ["derive"] }
|
||||||
serde_json = "1.0.107"
|
serde_json = "1.0.107"
|
||||||
sqlx = { version = "0.8.3", features = ["runtime-tokio", "postgres"] }
|
sqlx = { version = "0.8.3", features = ["runtime-tokio", "postgres"] }
|
||||||
tokio = { version = "1.32.0", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1.45.0", features = ["macros", "rt-multi-thread", "signal"] }
|
||||||
|
|
28
src/main.rs
28
src/main.rs
|
@ -28,6 +28,7 @@ use axum::{
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::{Value, json};
|
use serde_json::{Value, json};
|
||||||
use sqlx::{PgExecutor, PgPool, postgres::PgPoolOptions};
|
use sqlx::{PgExecutor, PgPool, postgres::PgPoolOptions};
|
||||||
|
use tokio::signal;
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||||
|
@ -88,17 +89,40 @@ async fn main() {
|
||||||
let mut bind_with = "0.0.0.0:".to_owned();
|
let mut bind_with = "0.0.0.0:".to_owned();
|
||||||
bind_with += &listen_port;
|
bind_with += &listen_port;
|
||||||
let listener = tokio::net::TcpListener::bind(bind_with).await.unwrap();
|
let listener = tokio::net::TcpListener::bind(bind_with).await.unwrap();
|
||||||
axum::serve(listener, app).await.unwrap();
|
axum::serve(listener, app)
|
||||||
|
.with_graceful_shutdown(shutdown_signal())
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn root() -> &'static str {
|
async fn root() -> &'static str {
|
||||||
"KOreader sync server"
|
"KOReader sync server"
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn version() -> &'static str {
|
async fn version() -> &'static str {
|
||||||
VERSION
|
VERSION
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn shutdown_signal() {
|
||||||
|
let ctrl_c = async {
|
||||||
|
signal::ctrl_c()
|
||||||
|
.await
|
||||||
|
.expect("Failed to install CTRL-C handler");
|
||||||
|
};
|
||||||
|
|
||||||
|
let terminate = async {
|
||||||
|
signal::unix::signal(signal::unix::SignalKind::terminate())
|
||||||
|
.expect("Failed to install Terminate handler")
|
||||||
|
.recv()
|
||||||
|
.await;
|
||||||
|
};
|
||||||
|
|
||||||
|
tokio::select! {
|
||||||
|
_ = ctrl_c => {},
|
||||||
|
_ = terminate => {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async fn create_user(
|
async fn create_user(
|
||||||
State(db_pool): State<PgPool>,
|
State(db_pool): State<PgPool>,
|
||||||
Json(payload): Json<User>,
|
Json(payload): Json<User>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue