1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-12-22 16:16:40 +00:00

add multiple apps example

This commit is contained in:
Nikolay Kim 2017-12-01 23:32:15 -08:00
parent 3ffd36eee2
commit 1a5df7192e
3 changed files with 28 additions and 2 deletions

View file

@ -68,7 +68,7 @@ fn main() {
))
// register simple handle r, handle all methods
.handler("/index.html", index)
// with path parameters
// with path parameters
.resource("/user/{name}/", |r| r.handler(Method::GET, with_param))
// async handler
.resource("/async/{name}", |r| r.async(Method::GET, index_async))

View file

@ -2,7 +2,7 @@
[Quickstart](./qs_1.md)
- [Getting Started](./qs_2.md)
- [Actix application](./qs_3.md)
- [Application](./qs_3.md)
- [Handler](./qs_4.md)
- [Resources and Routes](./qs_5.md)
- [Application state](./qs_6.md)

View file

@ -20,3 +20,29 @@ has same url path prefix:
In this example application with `/prefix` prefix and `index.html` resource
get created. This resource is available as on `/prefix/index.html` url.
Multiple applications could be served with one server:
```rust
extern crate actix_web;
extern crate tokio_core;
use std::net::SocketAddr;
use actix_web::*;
use tokio_core::net::TcpStream;
fn main() {
HttpServer::<TcpStream, SocketAddr, _>::new(vec![
Application::default("/app1")
.resource("/", |r| r.get(|r| httpcodes::HTTPOk))
.finish(),
Application::default("/app2")
.resource("/", |r| r.get(|r| httpcodes::HTTPOk))
.finish(),
Application::default("/")
.resource("/", |r| r.get(|r| httpcodes::HTTPOk))
.finish(),
]);
}
```
All `/app1` requests route to first application, `/app2` to second and then all other to third.