mirror of
https://github.com/Steffo99/todocolors.git
synced 2024-11-22 08:14:18 +00:00
Endpoints which return the version now return a JSON object
This commit is contained in:
parent
823de0af36
commit
8bcedd9fbf
4 changed files with 23 additions and 10 deletions
|
@ -17,10 +17,10 @@ async fn main() {
|
|||
.expect("to be able to connect to Redis");
|
||||
|
||||
let router = axum::Router::new()
|
||||
.route("/", get(routes::root::version))
|
||||
.route("/version", get(routes::root::version))
|
||||
.route("/", post(routes::root::healthcheck))
|
||||
.route("/healthcheck", post(routes::root::healthcheck))
|
||||
.route("/", get(routes::version_route))
|
||||
.route("/version", get(routes::version_route))
|
||||
.route("/", post(routes::healthcheck_route))
|
||||
.route("/healthcheck", post(routes::healthcheck_route))
|
||||
.route("/board/:board/ws", get(routes::board::board_websocket))
|
||||
.layer(axum::Extension(rclient))
|
||||
.layer(tower_http::cors::CorsLayer::new()
|
||||
|
|
|
@ -1,2 +1,6 @@
|
|||
pub(crate) mod root;
|
||||
pub(crate) mod board;
|
||||
pub mod board;
|
||||
pub mod structs;
|
||||
pub(self) mod root;
|
||||
|
||||
pub(crate) use root::version as version_route;
|
||||
pub(crate) use root::healthcheck as healthcheck_route;
|
||||
|
|
|
@ -2,23 +2,26 @@ use axum::{Extension, Json};
|
|||
use axum::http::StatusCode;
|
||||
|
||||
use crate::outcome::{Response, LoggableOutcome};
|
||||
use crate::routes::structs::VersionInfo;
|
||||
|
||||
const MAJOR: u32 = pkg_version::pkg_version_major!();
|
||||
const MINOR: u32 = pkg_version::pkg_version_minor!();
|
||||
const PATCH: u32 = pkg_version::pkg_version_patch!();
|
||||
|
||||
fn compose_version() -> String {
|
||||
format!("{}.{}.{}", MAJOR, MINOR, PATCH)
|
||||
fn compose_version() -> VersionInfo {
|
||||
VersionInfo {
|
||||
version: format!("{}.{}.{}", MAJOR, MINOR, PATCH)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub async fn version() -> Response<Json<String>> {
|
||||
pub async fn version() -> Response<Json<VersionInfo>> {
|
||||
Ok(Json(compose_version()))
|
||||
}
|
||||
|
||||
pub async fn healthcheck(
|
||||
Extension(rclient): Extension<redis::Client>
|
||||
) -> Response<Json<String>> {
|
||||
) -> Response<Json<VersionInfo>> {
|
||||
let mut rconn = rclient.get_async_connection().await
|
||||
.log_err_to_error("Failed to connect to Redis")
|
||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||
|
|
6
todored/src/routes/structs.rs
Normal file
6
todored/src/routes/structs.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct VersionInfo {
|
||||
pub version: String,
|
||||
}
|
Loading…
Reference in a new issue