1
0
mirror of https://github.com/actix/actix-website synced 2025-02-17 10:13:31 +01:00

fix application examples

This commit is contained in:
Nikolay Kim 2018-05-24 09:31:40 -07:00
parent 20ea20ae31
commit ec11bf0db3
2 changed files with 27 additions and 27 deletions

View File

@ -5,21 +5,21 @@ use actix_web::{http::Method, server, App, HttpRequest, HttpResponse, Responder}
mod state; mod state;
fn make_app() { fn make_app() {
// <make_app> // <make_app>
fn index(req: HttpRequest) -> impl Responder { fn index(req: HttpRequest) -> impl Responder {
"Hello world!" "Hello world!"
} }
let app = App::new() let app = App::new()
.prefix("/app") .prefix("/app")
.resource("/index.html", |r| r.method(Method::GET).f(index)) .resource("/index.html", |r| r.method(Method::GET).f(index))
.finish() .finish()
// </make_app> // </make_app>
; ;
} }
fn run_server() { fn run_server() {
// <run_server> // <run_server>
let server = server::new(|| { let server = server::new(|| {
vec![ vec![
App::new() App::new()
@ -31,7 +31,7 @@ fn run_server() {
App::new().resource("/", |r| r.f(|r| HttpResponse::Ok())), App::new().resource("/", |r| r.f(|r| HttpResponse::Ok())),
] ]
}); });
// </run_server> // </run_server>
} }
fn main() { fn main() {

View File

@ -16,8 +16,8 @@ fn index(req: HttpRequest<AppState>) -> String {
// </setup> // </setup>
fn make_app() { fn make_app() {
// <make_app> // <make_app>
App::with_state(AppState { counter: Cell::new(0) }) App::with_state(AppState { counter: Cell::new(0) })
.resource("/", |r| r.method(http::Method::GET).f(index)) .resource("/", |r| r.method(http::Method::GET).f(index))
.finish() .finish()
// </make_app> // </make_app>
@ -29,27 +29,27 @@ use std::thread;
fn combine() { fn combine() {
thread::spawn(|| { thread::spawn(|| {
// <combine> // <combine>
struct State1; struct State1;
struct State2; struct State2;
fn main() { fn main() {
server::new(|| { server::new(|| {
vec![ vec![
App::with_state(State1) App::with_state(State1)
.prefix("/app1") .prefix("/app1")
.resource("/", |r| r.f(|r| HttpResponse::Ok())) .resource("/", |r| r.f(|r| HttpResponse::Ok()))
.boxed(), .boxed(),
App::with_state(State2) App::with_state(State2)
.prefix("/app2") .prefix("/app2")
.resource("/", |r| r.f(|r| HttpResponse::Ok())) .resource("/", |r| r.f(|r| HttpResponse::Ok()))
.boxed(), .boxed(),
] ]
}).bind("127.0.0.1:8080") }).bind("127.0.0.1:8080")
.unwrap() .unwrap()
.run() .run()
} }
// </combine> // </combine>
}); });
} }