1
0
mirror of https://github.com/actix/actix-website synced 2024-12-04 04:31:55 +01:00
actix-website/examples/application/src/main.rs

43 lines
841 B
Rust
Raw Normal View History

2018-05-23 22:01:33 +02:00
#![allow(unused)]
2018-05-23 21:28:12 +02:00
extern crate actix_web;
2018-05-24 05:39:15 +02:00
use actix_web::{http::Method, server, App, HttpRequest, HttpResponse, Responder};
2018-05-23 21:28:12 +02:00
2018-05-23 22:01:33 +02:00
mod state;
2018-06-08 06:08:11 +02:00
mod vh;
2018-05-23 22:01:33 +02:00
fn make_app() {
2018-05-24 18:31:40 +02:00
// <make_app>
2018-07-21 14:21:41 +02:00
fn index(req: &HttpRequest) -> impl Responder {
2018-05-27 19:49:14 +02:00
"Hello world!"
}
2018-05-23 21:28:12 +02:00
2018-05-27 19:49:14 +02:00
let app = App::new()
.prefix("/app")
.resource("/index.html", |r| r.method(Method::GET).f(index))
.finish()
2018-05-23 22:01:33 +02:00
// </make_app>
;
}
fn run_server() {
2018-05-24 18:31:40 +02:00
// <run_server>
2018-05-27 19:49:14 +02:00
let server = server::new(|| {
vec![
App::new()
.prefix("/app1")
.resource("/", |r| r.f(|r| HttpResponse::Ok())),
App::new()
.prefix("/app2")
.resource("/", |r| r.f(|r| HttpResponse::Ok())),
App::new().resource("/", |r| r.f(|r| HttpResponse::Ok())),
]
});
2018-05-24 18:31:40 +02:00
// </run_server>
2018-05-23 22:01:33 +02:00
}
2018-05-23 21:28:12 +02:00
fn main() {
2018-05-23 22:01:33 +02:00
make_app();
run_server();
state::test();
2018-05-23 21:28:12 +02:00
}