Skip to content

Commit

Permalink
consolidate routes, partly implement HTCPCP
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubmanczak committed Jul 8, 2024
1 parent 108cf01 commit 76b9ffe
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod routes;
mod setup;
use axum::Router;
use routes::routes;
use tokio::net::TcpListener;
use tracing::{error, info};

Expand All @@ -10,9 +11,7 @@ async fn main() {
setup::initialise_dotenv();
setup::initialise_sqlite_db_tables();

let app = Router::new()
.merge(routes::health::route())
.merge(routes::splash::randsplash_route());
let app = Router::new().merge(routes());

let addr = setup::get_socket_addr();
let listener = match TcpListener::bind(&addr).await {
Expand Down
6 changes: 4 additions & 2 deletions src/routes/health.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use axum::{http::StatusCode, routing::get, Router};

pub fn route() -> Router {
Router::new().route("/health", get(health()))
Router::new()
.route("/live", get(empty()))
.route("/health", get(empty()))
}

fn health() -> StatusCode {
fn empty() -> StatusCode {
StatusCode::OK
}
10 changes: 10 additions & 0 deletions src/routes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
use axum::Router;

pub mod health;
pub mod splash;
pub mod teapot;

pub fn routes() -> Router {
Router::new()
.merge(health::route())
.merge(splash::route())
.merge(teapot::route())
}
2 changes: 1 addition & 1 deletion src/routes/splash.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use axum::{routing::get, Router};

pub fn randsplash_route() -> Router {
pub fn route() -> Router {
Router::new().route("/splash", get(random_splash()))
}

Expand Down
11 changes: 11 additions & 0 deletions src/routes/teapot.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use axum::{http::StatusCode, routing::get, Router};

pub fn route() -> Router {
Router::new()
.route("/brew-coffee", get(refuse_to_brew_coffee()))
.route("/brew", get(refuse_to_brew_coffee()))
}

fn refuse_to_brew_coffee() -> StatusCode {
StatusCode::IM_A_TEAPOT
}

0 comments on commit 76b9ffe

Please sign in to comment.