using custom version of actix-codegen and cors for pow routes

This commit is contained in:
realaravinth
2021-05-25 14:34:24 +05:30
parent 0421cb681c
commit 72667bd2e1
26 changed files with 334 additions and 363 deletions

View File

@@ -25,10 +25,6 @@ pub enum Methods {
ProtectGet,
/// Protected POST handler
ProtectPost,
/// CORS allow all orgin GET handler
CorsAllowAllGet,
/// CORS allow all orgin PST handler
CorsAllowAllPost,
}
/// Defines resoures for [Methods]
@@ -67,29 +63,4 @@ 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),
);
};
}