mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-25 06:39:22 +02:00
refactor server router
This commit is contained in:
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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");
|
||||
|
Reference in New Issue
Block a user