scoped cors

This commit is contained in:
realaravinth
2021-04-12 10:25:52 +05:30
parent bbf182a918
commit c776092023
4 changed files with 38 additions and 15 deletions

View File

@@ -38,7 +38,8 @@ pub struct GetConfigPayload {
// API keys are mcaptcha actor names
#[post("/api/v1/mcaptcha/pow/config")]
#[post("/config")]
//#[post("/pow/config")]
pub async fn get_config(
payload: web::Json<GetConfigPayload>,
data: web::Data<Data>,
@@ -149,7 +150,7 @@ mod tests {
const NAME: &str = "powusrworks";
const PASSWORD: &str = "testingpas";
const EMAIL: &str = "randomuser@a.com";
const GET_URL: &str = "/api/v1/mcaptcha/pow/config";
const GET_URL: &str = "/api/v1/pow/config";
// const UPDATE_URL: &str = "/api/v1/mcaptcha/domain/token/duration/update";
{

View File

@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
//use actix_cors::Cors;
use actix_cors::Cors;
use actix_web::web;
pub mod get_config;
@@ -51,6 +51,27 @@ pub use super::mcaptcha::levels::I32Levels;
//}
pub fn services(cfg: &mut web::ServiceConfig) {
let captcha_api_cors = Cors::default()
.allow_any_origin()
.allowed_methods(vec!["POST"])
.allow_any_header()
.max_age(0)
.send_wildcard();
cfg.service(
web::scope("/api/v1/pow/")
.wrap(captcha_api_cors)
.configure(intenral_services),
);
// cfg.service(
// cfg.service(get_config::get_config);
// cfg.service(verify_pow::verify_pow);
// cfg.service(verify_token::validate_captcha_token);
}
fn intenral_services(cfg: &mut web::ServiceConfig) {
cfg.service(get_config::get_config);
cfg.service(verify_pow::verify_pow);
cfg.service(verify_token::validate_captcha_token);

View File

@@ -29,7 +29,7 @@ pub struct ValidationToken {
// API keys are mcaptcha actor names
#[post("/api/v1/mcaptcha/pow/verify")]
#[post("/verify")]
pub async fn verify_pow(
payload: web::Json<Work>,
data: web::Data<Data>,