1
0
mirror of https://github.com/actix/actix-website synced 2024-12-03 20:22:13 +01:00
actix-website/examples/application/src/main.rs

38 lines
766 B
Rust
Raw Normal View History

2019-06-13 09:24:25 +02:00
#![allow(unused_variables)]
use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer, 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
2019-06-13 09:24:25 +02:00
#[rustfmt::skip]
2018-05-23 22:01:33 +02:00
fn make_app() {
2019-06-13 09:24:25 +02:00
2018-05-24 18:31:40 +02:00
// <make_app>
2019-06-13 09:24:25 +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()
2019-06-13 09:24:25 +02:00
.service(web::scope("/app").route("/index.html", web::get().to(index)));
2018-05-23 22:01:33 +02:00
// </make_app>
2019-06-13 09:24:25 +02:00
2018-05-23 22:01:33 +02:00
}
2019-06-13 09:24:25 +02:00
#[rustfmt::skip]
2018-05-23 22:01:33 +02:00
fn run_server() {
2018-05-24 18:31:40 +02:00
// <run_server>
2019-06-13 09:24:25 +02:00
let server = HttpServer::new(|| {
App::new()
.service(web::scope("/app1").route("/", web::to(|| HttpResponse::Ok())))
.service(web::scope("/app2").route("/", web::to(|| HttpResponse::Ok())))
.route("/", web::to(|| HttpResponse::Ok()))
2018-05-27 19:49:14 +02:00
});
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
}