actix / actix/actix-web

Multiple `.service(` doesn't merge route patterns

Aperta
#3,778 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Rust
Stelle
24.8k
Fork
1.9k
Merge medio
23h 10m
PR unite (30g)
26

Descrizione

## Expected Behavior

I'm building a nice size Apache-2.0 OR MIT) application. Reads are insecure, writes are secured. Here's my server:

```rs
.service(
utoipa_actix_web::scope("/api/v0")
.wrap(actix_web::middleware::Compat::new(
actix_web_httpauth::middleware::HttpAuthentication::bearer(
rust_actix_diesel_auth_scaffold::middleware::bearer::validator,
),
))
/* Org */
.service(crawlcomply_backend::routes::org::upsert)
.service(crawlcomply_backend::routes::org::remove)
)
.service(
utoipa_actix_web::scope("/api/v0")
/* Org */
.service(crawlcomply_backend::routes::org::read_many)
)
```

## Current Behavior

`POST /api/v0/org` works, whereas `GET /api/v0/org` never hits the route function.

## Possible Solution

Merge routes

## Steps to Reproduce (for bugs)

```rs
actix_web::HttpServer::new(move || {
actix_web::App::new()
.into_utoipa_app()
.openapi(ApiDoc::openapi())
.map(|app| app.wrap(actix_web::middleware::Logger::default()))
.app_data(
actix_web::web::JsonConfig::default().error_handler(|err, _req| {
actix_web::error::InternalError::from_response(
"",
actix_web::HttpResponse::BadRequest()
.content_type("application/json")
.body(format!(r#"{{"error":"{}"}}"#, err)),
)
.into()
}),
)
.app_data(actix_web::web::Data::new(pool.clone()))
.service(
utoipa_actix_web::scope("/api/v0")
.wrap(actix_web::middleware::Compat::new(
actix_web_httpauth::middleware::HttpAuthentication::bearer(
rust_actix_diesel_auth_scaffold::middleware::bearer::validator,
),
))
/* Org */
.service(crawlcomply_backend::routes::org::upsert)
.service(crawlcomply_backend::routes::org::remove)
)
.service(
utoipa_actix_web::scope("/api/v0")
/* Org */
.service(crawlcomply_backend::routes::org::read)
.service(crawlcomply_backend::routes::org::read_many)
)
.openapi_service(|api| utoipa_scalar::Scalar::with_url("/scalar", api))
.into_app()
})
.bind((args.hostname.as_str(), args.port))?
.run()
.await
```

## Context

Trying to have one group of routes be authenticated only and another group of routes public.

## Your Environment

- Rust Version (I.e, output of `rustc -V`): rustc 1.92.0-nightly (caccb4d03 2025-09-24)
- Actix Web Version: 4.11.0

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.