1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-24 07:53:00 +01:00

update examples

This commit is contained in:
Nikolay Kim 2017-12-04 16:32:31 -08:00
parent 2950c90c77
commit fd6b243cd6
3 changed files with 11 additions and 11 deletions

View File

@ -34,9 +34,9 @@ fn main() {
// enable logger
.middleware(middlewares::Logger::default())
// register simple handler, handle all methods
.handler("/index.html", index)
.route("/index.html", |r| r.f(index))
// with path parameters
.resource("/", |r| r.handler(Method::GET, |req| {
.resource("/", |r| r.method(Method::GET).f(|req| {
httpcodes::HTTPFound
.build()
.header("LOCATION", "/index.html")

View File

@ -199,16 +199,16 @@ fn main() {
HttpServer::new(
Application::build("/", state)
// redirect to websocket.html
.resource("/", |r| r.handler(Method::GET, |req| {
.resource("/", |r| r.method(Method::GET).f(|req| {
httpcodes::HTTPFound
.build()
.header("LOCATION", "/static/websocket.html")
.body(Body::Empty)
}))
// websocket
.resource("/ws/", |r| r.get(chat_route))
.resource("/ws/", |r| r.route().f(chat_route))
// 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();
let _ = sys.run();

View File

@ -43,9 +43,9 @@ impl<S: 'static> Route<S> {
self.handler.handle(req)
}
/// Add match predicate to route.
pub fn p(&mut self, p: Box<Predicate<S>>) -> &mut Self {
self.preds.push(p);
/// Add method check to route. This method could be called multiple times.
pub fn method(&mut self, method: Method) -> &mut Self {
self.preds.push(pred::Method(method));
self
}
@ -57,9 +57,9 @@ impl<S: 'static> Route<S> {
self
}
/// Add method check to route. This method could be called multiple times.
pub fn method(&mut self, method: Method) -> &mut Self {
self.preds.push(pred::Method(method));
/// Add match predicate to route.
pub fn p(&mut self, p: Box<Predicate<S>>) -> &mut Self {
self.preds.push(p);
self
}