1
0
mirror of https://github.com/actix/actix-website synced 2024-11-23 16:31:08 +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;
fn make_app() {
// <make_app>
// <make_app>
fn index(req: HttpRequest) -> impl Responder {
"Hello world!"
}
let app = App::new()
.prefix("/app")
.resource("/index.html", |r| r.method(Method::GET).f(index))
.finish()
.prefix("/app")
.resource("/index.html", |r| r.method(Method::GET).f(index))
.finish()
// </make_app>
;
}
fn run_server() {
// <run_server>
// <run_server>
let server = server::new(|| {
vec![
App::new()
@ -31,7 +31,7 @@ fn run_server() {
App::new().resource("/", |r| r.f(|r| HttpResponse::Ok())),
]
});
// </run_server>
// </run_server>
}
fn main() {

View File

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