mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2024-11-23 18:05:54 +03:00
scoped cors
This commit is contained in:
parent
bbf182a918
commit
c776092023
4 changed files with 38 additions and 15 deletions
|
@ -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";
|
||||
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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>,
|
||||
|
|
23
src/main.rs
23
src/main.rs
|
@ -81,12 +81,12 @@ 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();
|
||||
// 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())
|
||||
|
@ -97,12 +97,13 @@ async fn main() -> std::io::Result<()> {
|
|||
.wrap(middleware::NormalizePath::new(
|
||||
middleware::normalize::TrailingSlash::Trim,
|
||||
))
|
||||
.configure(v1::pow::services)
|
||||
.configure(v1::services)
|
||||
.service(
|
||||
scope("/api/v1/pow")
|
||||
.wrap(captcha_api_cors)
|
||||
.configure(v1::pow::services),
|
||||
)
|
||||
//.service(
|
||||
// scope("/")
|
||||
// .wrap(captcha_api_cors)
|
||||
// .configure(v1::pow::services),
|
||||
//)
|
||||
.configure(docs::services)
|
||||
.configure(templates::services)
|
||||
.configure(static_assets::services)
|
||||
|
|
Loading…
Reference in a new issue