mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-13 02:55:39 +00:00
pow uses const routes
This commit is contained in:
@@ -17,12 +17,21 @@
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub enum Methods {
|
||||
/// GET hander
|
||||
Get,
|
||||
/// POST handler
|
||||
Post,
|
||||
/// Protected GET handler
|
||||
ProtectGet,
|
||||
/// Protected POST handler
|
||||
ProtectPost,
|
||||
/// CORS allow all orgin GET handler
|
||||
CorsAllowAllGet,
|
||||
/// CORS allow all orgin PST handler
|
||||
CorsAllowAllPost,
|
||||
}
|
||||
|
||||
/// Defines resoures for [Methods]
|
||||
#[macro_export]
|
||||
macro_rules! define_resource {
|
||||
($cfg:expr, $path:expr, Methods::Get, $to:expr) => {
|
||||
@@ -58,4 +67,29 @@ macro_rules! define_resource {
|
||||
.to($to),
|
||||
);
|
||||
};
|
||||
|
||||
($cfg:expr, $path:expr, Methods::CorsAllowAllGet, $cors:expr, $to:expr) => {
|
||||
$cfg.service(
|
||||
actix_web::web::resource($path)
|
||||
.wrap($cors)
|
||||
.guard(actix_web::guard::Get())
|
||||
.to($to),
|
||||
);
|
||||
};
|
||||
|
||||
($cfg:expr, $path:expr, Methods::CorsAllowAllPost, $to:expr) => {
|
||||
let cors = Cors::default()
|
||||
.allow_any_origin()
|
||||
.allowed_methods(vec!["POST"])
|
||||
.allow_any_header()
|
||||
.max_age(0)
|
||||
.send_wildcard();
|
||||
|
||||
$cfg.service(
|
||||
actix_web::web::resource($path)
|
||||
.wrap(cors)
|
||||
.guard(actix_web::guard::Post())
|
||||
.to($to),
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user