aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index e5cfb31..bd3ff32 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,5 @@
#![feature(exit_status_error)]
+pub mod api;
pub mod check;
pub mod log;
pub mod mail;
@@ -6,7 +7,13 @@ pub mod web;
use ::log::error;
use anyhow::{anyhow, Result};
-use axum::{response::Html, routing::get, Router};
+use api::make_json_response;
+use axum::{
+ http::HeaderMap,
+ response::{Html, IntoResponse},
+ routing::get,
+ Json, Router,
+};
use check::{check_loop, Check};
use chrono::{DateTime, Utc};
use mail::MailConfig;
@@ -72,7 +79,7 @@ async fn run() -> anyhow::Result<()> {
"/",
get({
let config = config.clone();
- move || async move {
+ move |headers: HeaderMap| async move {
(
[
(
@@ -81,7 +88,14 @@ async fn run() -> anyhow::Result<()> {
),
(REFRESH, format!("{}", config.interval)),
],
- Html(make_html_page(config.clone()).await),
+ if headers
+ .get("accept")
+ .map_or(false, |s| s == "application/json")
+ {
+ Json(make_json_response(config.clone()).await).into_response()
+ } else {
+ Html(make_html_page(config.clone()).await).into_response()
+ },
)
}
}),