mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-23 23:51:06 +01:00
update examples
This commit is contained in:
parent
2950c90c77
commit
fd6b243cd6
@ -34,9 +34,9 @@ fn main() {
|
|||||||
// enable logger
|
// enable logger
|
||||||
.middleware(middlewares::Logger::default())
|
.middleware(middlewares::Logger::default())
|
||||||
// register simple handler, handle all methods
|
// register simple handler, handle all methods
|
||||||
.handler("/index.html", index)
|
.route("/index.html", |r| r.f(index))
|
||||||
// with path parameters
|
// with path parameters
|
||||||
.resource("/", |r| r.handler(Method::GET, |req| {
|
.resource("/", |r| r.method(Method::GET).f(|req| {
|
||||||
httpcodes::HTTPFound
|
httpcodes::HTTPFound
|
||||||
.build()
|
.build()
|
||||||
.header("LOCATION", "/index.html")
|
.header("LOCATION", "/index.html")
|
||||||
|
@ -199,16 +199,16 @@ fn main() {
|
|||||||
HttpServer::new(
|
HttpServer::new(
|
||||||
Application::build("/", state)
|
Application::build("/", state)
|
||||||
// redirect to websocket.html
|
// redirect to websocket.html
|
||||||
.resource("/", |r| r.handler(Method::GET, |req| {
|
.resource("/", |r| r.method(Method::GET).f(|req| {
|
||||||
httpcodes::HTTPFound
|
httpcodes::HTTPFound
|
||||||
.build()
|
.build()
|
||||||
.header("LOCATION", "/static/websocket.html")
|
.header("LOCATION", "/static/websocket.html")
|
||||||
.body(Body::Empty)
|
.body(Body::Empty)
|
||||||
}))
|
}))
|
||||||
// websocket
|
// websocket
|
||||||
.resource("/ws/", |r| r.get(chat_route))
|
.resource("/ws/", |r| r.route().f(chat_route))
|
||||||
// static resources
|
// static resources
|
||||||
.route("/static", fs::StaticFiles::new("static/", true)))
|
.route("/static", |r| r.h(fs::StaticFiles::new("static/", true))))
|
||||||
.serve::<_, ()>("127.0.0.1:8080").unwrap();
|
.serve::<_, ()>("127.0.0.1:8080").unwrap();
|
||||||
|
|
||||||
let _ = sys.run();
|
let _ = sys.run();
|
||||||
|
12
src/route.rs
12
src/route.rs
@ -43,9 +43,9 @@ impl<S: 'static> Route<S> {
|
|||||||
self.handler.handle(req)
|
self.handler.handle(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add match predicate to route.
|
/// Add method check to route. This method could be called multiple times.
|
||||||
pub fn p(&mut self, p: Box<Predicate<S>>) -> &mut Self {
|
pub fn method(&mut self, method: Method) -> &mut Self {
|
||||||
self.preds.push(p);
|
self.preds.push(pred::Method(method));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,9 +57,9 @@ impl<S: 'static> Route<S> {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add method check to route. This method could be called multiple times.
|
/// Add match predicate to route.
|
||||||
pub fn method(&mut self, method: Method) -> &mut Self {
|
pub fn p(&mut self, p: Box<Predicate<S>>) -> &mut Self {
|
||||||
self.preds.push(pred::Method(method));
|
self.preds.push(p);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user