1
0
mirror of https://github.com/actix/examples synced 2025-02-02 17:39:05 +01:00
This commit is contained in:
Gorm Casper 2018-07-09 20:18:31 +02:00
parent 14baeff358
commit ab7736c790
6 changed files with 51 additions and 0 deletions

View File

@ -45,6 +45,7 @@ script:
cd http-proxy && cargo check && cd .. cd http-proxy && cargo check && cd ..
cd json && cargo check && cd .. cd json && cargo check && cd ..
cd juniper && cargo check && cd .. cd juniper && cargo check && cd ..
cd middleware && cargo check && cd ..
cd multipart && cargo check && cd .. cd multipart && cargo check && cd ..
cd protobuf && cargo check && cd .. cd protobuf && cargo check && cd ..
cd r2d2 && cargo check && cd .. cd r2d2 && cargo check && cd ..

8
Cargo.lock generated
View File

@ -1038,6 +1038,14 @@ name = "memoffset"
version = "0.2.1" version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "middleware-example"
version = "0.1.0"
dependencies = [
"actix 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)",
"actix-web 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "mime" name = "mime"
version = "0.3.7" version = "0.3.7"

View File

@ -12,6 +12,7 @@ members = [
"http-proxy", "http-proxy",
"json", "json",
"juniper", "juniper",
"middleware",
"multipart", "multipart",
"protobuf", "protobuf",
"r2d2", "r2d2",

8
middleware/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "middleware-example"
version = "0.1.0"
authors = ["Gorm Casper <gcasper@gmail.com>"]
[dependencies]
actix = "0.5"
actix-web = "^0.6"

20
middleware/src/main.rs Normal file
View File

@ -0,0 +1,20 @@
extern crate actix;
extern crate actix_web;
use actix_web::{server, App};
mod simple;
fn main() {
let sys = actix::System::new("middleware-example");
let _addr = server::new(|| {
App::new()
.middleware(simple::SayHi)
.resource("/index.html", |r| r.f(|_| "Hello, middleware!"))
}).bind("0.0.0.0:8080")
.unwrap()
.start();
let _ = sys.run();
}

13
middleware/src/simple.rs Normal file
View File

@ -0,0 +1,13 @@
extern crate actix_web;
use actix_web::middleware::{Middleware, Started};
use actix_web::{HttpRequest, Result};
pub struct SayHi;
impl<S> Middleware<S> for SayHi {
fn start(&self, _req: &mut HttpRequest<S>) -> Result<Started> {
println!("Hi");
Ok(Started::Done)
}
}