Skip to content

Instantly share code, notes, and snippets.

@oscartbeaumont
Created June 13, 2021 17:27
Show Gist options
  • Save oscartbeaumont/471772733c83efab04238a4b189be751 to your computer and use it in GitHub Desktop.
Save oscartbeaumont/471772733c83efab04238a4b189be751 to your computer and use it in GitHub Desktop.
Rust Actix Scope Middleware
[package]
name = "rust-actix-scope-middleware-bug"
version = "0.1.0"
authors = ["Oscar Beaumont <[email protected]>"]
edition = "2018"
[dependencies]
actix-web = "3.3.2"
use actix_web::{middleware, web, App, HttpServer, Responder};
async fn index() -> impl Responder {
"Hello World"
}
async fn index_compressed() -> impl Responder {
"Hello World Compressed!"
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new().route("/", web::get().to(index)).service(
web::scope("")
.wrap(middleware::Compress::default())
.route("/compressed", web::get().to(index_compressed)),
)
})
.bind(("0.0.0.0", 9000))?
.run()
.await
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment