Skip to content

Commit

Permalink
feat: new generate_204 api (#44)
Browse files Browse the repository at this point in the history
* feat: new `generate_204` api

* feat(docker): health check

* fix(dockerfile): add comma
  • Loading branch information
kwaa committed Jun 5, 2024
1 parent df6e933 commit 289f7f4
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 2 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ tracing-json = ["hatsu_tracing/json"]
[workspace]
members = [
".",
"crates/api",
"crates/api_admin",
"crates/api_apub",
"crates/api_mastodon",
Expand All @@ -66,6 +67,7 @@ members = [
]

[workspace.dependencies]
hatsu_api = { path = "./crates/api" }
hatsu_api_admin = { path = "./crates/api_admin" }
hatsu_api_apub = { path = "./crates/api_apub" }
hatsu_api_mastodon = { path = "./crates/api_mastodon" }
Expand Down
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ RUN install_packages openssl libssl-dev ca-certificates curl && \
curl -sSf https://just.systems/install.sh | bash -s -- --tag 1.23.0 --to /usr/local/bin && \
chmod +x /app/hatsu

ENTRYPOINT [ "/app/hatsu" ]
ENV HATSU_LISTEN_PORT=3939
EXPOSE $HATSU_LISTEN_PORT

HEALTHCHECK CMD [ "curl", "--fail", "http://localhost:${HATSU_LISTEN_PORT}/api/v0/generate_204" ]

EXPOSE 3939
ENTRYPOINT [ "/app/hatsu" ]

STOPSIGNAL SIGTERM
21 changes: 21 additions & 0 deletions crates/api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "hatsu_api"
version.workspace = true
edition.workspace = true
publish.workspace = true
readme.workspace = true
license.workspace = true
authors.workspace = true
description.workspace = true
documentation.workspace = true
homepage.workspace = true
repository.workspace = true

[lib]
name = "hatsu_api"
path = "src/lib.rs"

[dependencies]
axum = { workspace = true }
url = { workspace = true }
utoipa = { workspace = true }
4 changes: 4 additions & 0 deletions crates/api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// pub mod entities;
pub mod routes;

pub use routes::routes;
15 changes: 15 additions & 0 deletions crates/api/src/routes/generate_204.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use axum::{debug_handler, http::StatusCode};

/// Generate 204 Response
#[utoipa::path(
get,
tag = "hatsu",
path = "/api/v0/generate_204",
responses(
(status = NO_CONTENT, description = "NO_CONTENT"),
)
)]
#[debug_handler]
pub async fn generate_204() -> StatusCode {
StatusCode::NO_CONTENT
}
9 changes: 9 additions & 0 deletions crates/api/src/routes/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use axum::{routing::get, Router};

pub mod generate_204;

use generate_204::generate_204;

pub fn routes() -> Router {
Router::new().route("/api/v0/generate_204", get(generate_204))
}
1 change: 1 addition & 0 deletions crates/backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ name = "hatsu_backend"
path = "src/lib.rs"

[dependencies]
hatsu_api = { workspace = true }
hatsu_api_admin = { workspace = true }
hatsu_api_apub = { workspace = true }
hatsu_api_mastodon = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions crates/backend/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ async fn root() -> Response<String> {

pub fn routes() -> Router {
Router::new()
.merge(hatsu_api::routes())
.merge(hatsu_api_admin::routes())
.merge(hatsu_api_apub::routes())
.merge(hatsu_api_mastodon::routes())
Expand Down
1 change: 1 addition & 0 deletions crates/openapi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ name = "hatsu_openapi"
path = "src/lib.rs"

[dependencies]
hatsu_api = { workspace = true }
hatsu_api_admin = { workspace = true }
hatsu_api_apub = { workspace = true }
hatsu_api_mastodon = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions crates/openapi/src/apidoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use utoipa::{
#[openapi(
info(title = "Hatsu"),
paths(
hatsu_api::routes::generate_204::generate_204,
hatsu_api_admin::routes::create_account::create_account,
hatsu_api_admin::routes::remove_account::remove_account,
hatsu_api_apub::activities::activity::activity,
Expand Down

0 comments on commit 289f7f4

Please sign in to comment.