surrealpatch/src/net/head.rs

42 lines
996 B
Rust
Raw Normal View History

2022-02-09 13:55:21 +00:00
use crate::cnf::PKG_NAME;
use crate::cnf::PKG_VERS;
use crate::cnf::SERVER_NAME;
const ID: &'static str = "ID";
const NS: &'static str = "NS";
const DB: &'static str = "DB";
const SERVER: &'static str = "Server";
const VERSION: &'static str = "Version";
2020-06-29 15:36:01 +00:00
pub fn version() -> warp::filters::reply::WithHeader {
2022-02-09 13:55:21 +00:00
let val = format!("{}-{}", PKG_NAME, PKG_VERS);
warp::reply::with::header(VERSION, val)
2020-06-29 15:36:01 +00:00
}
2021-03-29 15:43:37 +00:00
pub fn server() -> warp::filters::reply::WithHeader {
2022-02-09 13:55:21 +00:00
warp::reply::with::header(SERVER, SERVER_NAME)
2020-06-29 15:36:01 +00:00
}
pub fn cors() -> warp::filters::cors::Builder {
warp::cors()
.max_age(86400)
.allow_any_origin()
.allow_methods(vec![
http::Method::GET,
http::Method::PUT,
http::Method::POST,
http::Method::PATCH,
http::Method::DELETE,
http::Method::OPTIONS,
])
.allow_headers(vec![
http::header::ACCEPT,
http::header::AUTHORIZATION,
http::header::CONTENT_TYPE,
http::header::ORIGIN,
2022-02-09 13:55:21 +00:00
NS.parse().unwrap(),
DB.parse().unwrap(),
ID.parse().unwrap(),
2020-06-29 15:36:01 +00:00
])
}