mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2024-11-27 20:07:58 +03:00
cors for pow routes
This commit is contained in:
parent
0d1ba0d150
commit
8851b1f7b7
4 changed files with 40 additions and 10 deletions
|
@ -52,11 +52,6 @@ pub fn services(cfg: &mut ServiceConfig) {
|
||||||
// duration
|
// duration
|
||||||
cfg.service(mcaptcha::duration::update_duration);
|
cfg.service(mcaptcha::duration::update_duration);
|
||||||
cfg.service(mcaptcha::duration::get_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)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//use actix_cors::Cors;
|
//use actix_cors::Cors;
|
||||||
//use lazy_static::lazy_static;
|
use actix_web::web;
|
||||||
|
|
||||||
pub mod get_config;
|
pub mod get_config;
|
||||||
pub mod verify_pow;
|
pub mod verify_pow;
|
||||||
|
@ -34,3 +34,24 @@ pub use super::mcaptcha::levels::I32Levels;
|
||||||
// .max_age(0)
|
// .max_age(0)
|
||||||
// .send_wildcard();
|
// .send_wildcard();
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
//pub fn services(cfg: &mut web::ServiceConfig) -> web::Scope<impl actix_service::ServiceFactory> {
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ pub struct CaptchaValidateResp {
|
||||||
|
|
||||||
// API keys are mcaptcha actor names
|
// API keys are mcaptcha actor names
|
||||||
|
|
||||||
#[post("/api/v1/siteverify")]
|
#[post("/api/v1/pow/siteverify")]
|
||||||
pub async fn validate_captcha_token(
|
pub async fn validate_captcha_token(
|
||||||
payload: web::Json<VerifyCaptchaResult>,
|
payload: web::Json<VerifyCaptchaResult>,
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
|
@ -64,7 +64,7 @@ mod tests {
|
||||||
const EMAIL: &str = "verifyuser@enter.com";
|
const EMAIL: &str = "verifyuser@enter.com";
|
||||||
const VERIFY_CAPTCHA_URL: &str = "/api/v1/mcaptcha/pow/verify";
|
const VERIFY_CAPTCHA_URL: &str = "/api/v1/mcaptcha/pow/verify";
|
||||||
const GET_URL: &str = "/api/v1/mcaptcha/pow/config";
|
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";
|
// const UPDATE_URL: &str = "/api/v1/mcaptcha/domain/token/duration/update";
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
18
src/main.rs
18
src/main.rs
|
@ -16,10 +16,11 @@
|
||||||
*/
|
*/
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
|
use actix_cors::Cors;
|
||||||
use actix_identity::{CookieIdentityPolicy, IdentityService};
|
use actix_identity::{CookieIdentityPolicy, IdentityService};
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
client::Client, error::InternalError, http::StatusCode, middleware, web::JsonConfig, App,
|
client::Client, error::InternalError, http::StatusCode, middleware, web::scope,
|
||||||
HttpServer,
|
web::JsonConfig, App, HttpServer,
|
||||||
};
|
};
|
||||||
//use awc::Client;
|
//use awc::Client;
|
||||||
use cache_buster::Files as FileMap;
|
use cache_buster::Files as FileMap;
|
||||||
|
@ -79,6 +80,14 @@ async fn main() -> std::io::Result<()> {
|
||||||
|
|
||||||
HttpServer::new(move || {
|
HttpServer::new(move || {
|
||||||
let client = Client::default();
|
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()
|
App::new()
|
||||||
.wrap(middleware::Logger::default())
|
.wrap(middleware::Logger::default())
|
||||||
.wrap(get_identity_service())
|
.wrap(get_identity_service())
|
||||||
|
@ -89,6 +98,11 @@ async fn main() -> std::io::Result<()> {
|
||||||
middleware::normalize::TrailingSlash::Trim,
|
middleware::normalize::TrailingSlash::Trim,
|
||||||
))
|
))
|
||||||
.configure(v1::services)
|
.configure(v1::services)
|
||||||
|
.service(
|
||||||
|
scope("/api/v1/pow")
|
||||||
|
.wrap(captcha_api_cors)
|
||||||
|
.configure(v1::pow::services),
|
||||||
|
)
|
||||||
.configure(docs::services)
|
.configure(docs::services)
|
||||||
.configure(templates::services)
|
.configure(templates::services)
|
||||||
.configure(static_assets::services)
|
.configure(static_assets::services)
|
||||||
|
|
Loading…
Reference in a new issue