fix cors #2
This commit is contained in:
parent
faa21a5d7e
commit
f9a4a30e61
1 changed files with 31 additions and 1 deletions
|
@ -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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue