Compare commits

..

3 Commits

Author SHA1 Message Date
45755c498c add content-type to JSON response 2025-03-17 22:10:43 +01:00
452c292570 adjust Traefik header for legacy Traefik pre-v2
Our modern infrastructure is not yet ready for this, apparently.
2025-03-17 21:52:57 +01:00
64ccd0a51b add CORS 2025-03-05 23:17:15 +01:00
2 changed files with 16 additions and 4 deletions

View File

@ -9,6 +9,12 @@ services:
- traefik.port=3000
- traefik.frontend.passHostHeader=true
- traefik.enable=true
- traefik.frontend.headers.customResponseHeaders=Access-Control-Allow-Origin:*
# NOTE: This is for Traefik v2, apparently.
- traefik.http.middlewares.cors.headers.accesscontrolallowmethods=GET,OPTIONS,PUT
- traefik.http.middlewares.cors.headers.accesscontrolalloworiginlist=https://chaospott.de
- traefik.http.middlewares.cors.headers.accesscontrolmaxage=100
- traefik.http.middlewares.cors.headers.addvaryheader=true
networks:
- extern

View File

@ -4,7 +4,8 @@ use std::io::prelude::*;
use std::path::Path;
use axum::{
http::StatusCode,
body::Body,
http::{Response, StatusCode},
routing::{get, post},
Json, Router,
};
@ -64,12 +65,17 @@ fn write_status(s: Status) -> String {
// Just output the current file. We assume it to be consistent.
// It may cease to or not yet exist. Then create an initial status and persist.
async fn root() -> String {
if std::path::Path::new(STATUS_FILE).exists() {
async fn root() -> Response<Body> {
let res = if std::path::Path::new(STATUS_FILE).exists() {
read_to_string(STATUS_FILE).unwrap_or(String::from("KAPOTT"))
} else {
write_status(init_status())
}
};
Response::builder()
.status(StatusCode::OK)
.header("Content-Type", "application/json")
.body(Body::from(res))
.unwrap()
}
// Input type for the API: Both fields are optional.