diff --git a/src/api/v1/mod.rs b/src/api/v1/mod.rs index c35b6bf1..e20a7759 100644 --- a/src/api/v1/mod.rs +++ b/src/api/v1/mod.rs @@ -52,11 +52,6 @@ pub fn services(cfg: &mut ServiceConfig) { // duration cfg.service(mcaptcha::duration::update_duration); cfg.service(mcaptcha::duration::get_duration); - - // pow - cfg.service(pow::get_config::get_config); - cfg.service(pow::verify_pow::verify_pow); - cfg.service(pow::verify_token::validate_captcha_token); } #[cfg(test)] diff --git a/src/api/v1/pow/mod.rs b/src/api/v1/pow/mod.rs index e1e60e03..18132fc1 100644 --- a/src/api/v1/pow/mod.rs +++ b/src/api/v1/pow/mod.rs @@ -16,7 +16,7 @@ */ //use actix_cors::Cors; -//use lazy_static::lazy_static; +use actix_web::web; pub mod get_config; pub mod verify_pow; @@ -34,3 +34,24 @@ pub use super::mcaptcha::levels::I32Levels; // .max_age(0) // .send_wildcard(); //} + +//pub fn services(cfg: &mut web::ServiceConfig) -> web::Scope { +// let captcha_api_cors = Cors::default() +// .allow_any_origin() +// .allowed_methods(vec!["POST"]) +// .allow_any_header() +// .max_age(0) +// .send_wildcard(); +// +// web::scope("/api/v1/pow/*") +// .wrap(captcha_api_cors) +// .configure(pow_services) +// +// // pow +//} + +pub fn services(cfg: &mut web::ServiceConfig) { + cfg.service(get_config::get_config); + cfg.service(verify_pow::verify_pow); + cfg.service(verify_token::validate_captcha_token); +} diff --git a/src/api/v1/pow/verify_token.rs b/src/api/v1/pow/verify_token.rs index 4ed27916..c2f69fed 100644 --- a/src/api/v1/pow/verify_token.rs +++ b/src/api/v1/pow/verify_token.rs @@ -29,7 +29,7 @@ pub struct CaptchaValidateResp { // API keys are mcaptcha actor names -#[post("/api/v1/siteverify")] +#[post("/api/v1/pow/siteverify")] pub async fn validate_captcha_token( payload: web::Json, data: web::Data, @@ -64,7 +64,7 @@ mod tests { const EMAIL: &str = "verifyuser@enter.com"; const VERIFY_CAPTCHA_URL: &str = "/api/v1/mcaptcha/pow/verify"; const GET_URL: &str = "/api/v1/mcaptcha/pow/config"; - const VERIFY_TOKEN_URL: &str = "/api/v1/siteverify"; + const VERIFY_TOKEN_URL: &str = "/api/v1/pow/siteverify"; // const UPDATE_URL: &str = "/api/v1/mcaptcha/domain/token/duration/update"; { diff --git a/src/main.rs b/src/main.rs index 86aed5ee..07bc5879 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,10 +16,11 @@ */ use std::env; +use actix_cors::Cors; use actix_identity::{CookieIdentityPolicy, IdentityService}; use actix_web::{ - client::Client, error::InternalError, http::StatusCode, middleware, web::JsonConfig, App, - HttpServer, + client::Client, error::InternalError, http::StatusCode, middleware, web::scope, + web::JsonConfig, App, HttpServer, }; //use awc::Client; use cache_buster::Files as FileMap; @@ -79,6 +80,14 @@ async fn main() -> std::io::Result<()> { HttpServer::new(move || { let client = Client::default(); + + let captcha_api_cors = Cors::default() + .allow_any_origin() + .allowed_methods(vec!["POST"]) + .allow_any_header() + .max_age(0) + .send_wildcard(); + App::new() .wrap(middleware::Logger::default()) .wrap(get_identity_service()) @@ -89,6 +98,11 @@ async fn main() -> std::io::Result<()> { middleware::normalize::TrailingSlash::Trim, )) .configure(v1::services) + .service( + scope("/api/v1/pow") + .wrap(captcha_api_cors) + .configure(v1::pow::services), + ) .configure(docs::services) .configure(templates::services) .configure(static_assets::services)