mirror of
https://github.com/actix/examples
synced 2025-02-02 09:39:03 +01:00
init
This commit is contained in:
parent
14baeff358
commit
ab7736c790
@ -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
8
Cargo.lock
generated
@ -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"
|
||||||
|
@ -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
8
middleware/Cargo.toml
Normal 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
20
middleware/src/main.rs
Normal 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
13
middleware/src/simple.rs
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user