Compare commits
3 Commits
2b03c60ef2
...
main
Author | SHA1 | Date | |
---|---|---|---|
45755c498c | |||
452c292570 | |||
64ccd0a51b |
@ -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
|
||||
|
||||
|
14
src/main.rs
14
src/main.rs
@ -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.
|
||||
|
Reference in New Issue
Block a user