mirror of
https://github.com/fafhrd91/actix-web
synced 2025-01-18 05:41:50 +01:00
add multiple apps example
This commit is contained in:
parent
3ffd36eee2
commit
1a5df7192e
@ -68,7 +68,7 @@ fn main() {
|
|||||||
))
|
))
|
||||||
// register simple handle r, handle all methods
|
// register simple handle r, handle all methods
|
||||||
.handler("/index.html", index)
|
.handler("/index.html", index)
|
||||||
// with path parameters
|
// with path parameters
|
||||||
.resource("/user/{name}/", |r| r.handler(Method::GET, with_param))
|
.resource("/user/{name}/", |r| r.handler(Method::GET, with_param))
|
||||||
// async handler
|
// async handler
|
||||||
.resource("/async/{name}", |r| r.async(Method::GET, index_async))
|
.resource("/async/{name}", |r| r.async(Method::GET, index_async))
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
[Quickstart](./qs_1.md)
|
[Quickstart](./qs_1.md)
|
||||||
- [Getting Started](./qs_2.md)
|
- [Getting Started](./qs_2.md)
|
||||||
- [Actix application](./qs_3.md)
|
- [Application](./qs_3.md)
|
||||||
- [Handler](./qs_4.md)
|
- [Handler](./qs_4.md)
|
||||||
- [Resources and Routes](./qs_5.md)
|
- [Resources and Routes](./qs_5.md)
|
||||||
- [Application state](./qs_6.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
|
In this example application with `/prefix` prefix and `index.html` resource
|
||||||
get created. This resource is available as on `/prefix/index.html` url.
|
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…
x
Reference in New Issue
Block a user