1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-06-25 09:59:21 +02:00

refactor server router

This commit is contained in:
Nikolay Kim
2017-10-21 18:54:24 -07:00
parent 0d6e42e748
commit 6a33b65f02
10 changed files with 173 additions and 373 deletions

View File

@ -20,7 +20,7 @@ impl Route for MyRoute {
let multipart = match req.multipart(payload) {
Ok(mp) => mp,
Err(e) => return Reply::reply(e),
Err(e) => return e.into(),
};
// get Multipart stream
@ -68,13 +68,12 @@ fn main() {
let sys = actix::System::new("multipart-example");
HttpServer::new(
RoutingMap::default()
.app("/", Application::default()
.resource("/multipart", |r| {
r.post::<MyRoute>();
})
.finish())
.finish())
vec![
Application::default("/")
.resource("/multipart", |r| {
r.post::<MyRoute>();
}).finish()
])
.serve::<_, ()>("127.0.0.1:8080").unwrap();
let _ = sys.run();

View File

@ -212,22 +212,19 @@ fn main() {
// Create Http server with websocket support
HttpServer::new(
RoutingMap::default()
.app("/", Application::builder(state)
// redirect to websocket.html
.resource("/", |r|
r.handler(Method::GET, |req, payload, state| {
httpcodes::HTTPFound
.builder()
.header("LOCATION", "/static/websocket.html")
.body(Body::Empty)
}))
// websocket
.resource("/ws/", |r| r.get::<WsChatSession>())
// static resources
.route_handler("/static", StaticFiles::new("static/", true))
.finish())
.finish())
Application::builder("/", state)
// redirect to websocket.html
.resource("/", |r|
r.handler(Method::GET, |req, payload, state| {
httpcodes::HTTPFound
.builder()
.header("LOCATION", "/static/websocket.html")
.body(Body::Empty)
}))
// websocket
.resource("/ws/", |r| r.get::<WsChatSession>())
// static resources
.route_handler("/static", StaticFiles::new("static/", true)))
.serve::<_, ()>("127.0.0.1:8080").unwrap();
let _ = sys.run();

View File

@ -58,17 +58,13 @@ impl Handler<ws::Message> for MyWebSocket {
}
}
fn main() {
let sys = actix::System::new("ws-example");
HttpServer::new(
RoutingMap::default()
Application::default("/")
.resource("/ws/", |r| r.get::<MyWebSocket>())
.app("/", Application::default()
.route_handler("/", StaticFiles::new("static/", true))
.finish())
.finish())
.route_handler("/", StaticFiles::new("static/", true)))
.serve::<_, ()>("127.0.0.1:8080").unwrap();
println!("Started http server: 127.0.0.1:8080");