This commit is contained in:
creations 2025-05-31 19:10:53 -04:00
parent faa21a5d7e
commit f9a4a30e61
Signed by: creations
GPG key ID: 8F553AA4320FC711

View file

@ -1,13 +1,43 @@
use crate::db::AppState;
use axum::{Router, routing::get};
use axum::{
http::{HeaderValue, StatusCode},
response::Response,
routing::{get, options},
Router,
};
pub mod auth;
mod timezone;
async fn preflight_handler() -> Response {
let mut res = Response::new("".into());
let headers = res.headers_mut();
headers.insert("access-control-allow-origin", HeaderValue::from_static("*"));
headers.insert(
"access-control-allow-methods",
HeaderValue::from_static("GET, POST, OPTIONS"),
);
headers.insert(
"access-control-allow-headers",
HeaderValue::from_static("Content-Type, Authorization"),
);
headers.insert(
"access-control-allow-credentials",
HeaderValue::from_static("true"),
);
headers.insert("vary", HeaderValue::from_static("Origin"));
*res.status_mut() = StatusCode::OK;
res
}
pub fn all() -> Router<AppState> {
Router::new()
.route("/get", get(timezone::get_timezone))
.route("/set", get(timezone::set_timezone))
.route("/set", options(preflight_handler))
.route("/delete", get(timezone::delete_timezone))
.route("/list", get(timezone::list_timezones))
.route("/auth/discord", get(auth::start_oauth))