mirror of
https://github.com/actix/actix-web.git
synced 2024-12-23 00:26:34 +00:00
add multiple apps example
This commit is contained in:
parent
3ffd36eee2
commit
1a5df7192e
3 changed files with 28 additions and 2 deletions
|
@ -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))
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue