2019-03-10 19:19:50 -07:00
|
|
|
use actix_web::{web, App, HttpServer};
|
2018-07-09 20:18:31 +02:00
|
|
|
|
2018-07-09 21:36:03 +02:00
|
|
|
#[allow(dead_code)]
|
|
|
|
mod redirect;
|
|
|
|
#[allow(dead_code)]
|
2018-07-09 20:18:31 +02:00
|
|
|
mod simple;
|
|
|
|
|
2019-03-10 19:19:50 -07:00
|
|
|
fn main() -> std::io::Result<()> {
|
|
|
|
std::env::set_var("RUST_LOG", "actix_web=debug");
|
|
|
|
env_logger::init();
|
2018-07-09 20:18:31 +02:00
|
|
|
|
2019-03-10 19:19:50 -07:00
|
|
|
HttpServer::new(|| {
|
2018-07-09 20:18:31 +02:00
|
|
|
App::new()
|
2019-03-10 19:19:50 -07:00
|
|
|
.middleware(redirect::CheckLogin)
|
2018-07-09 20:18:31 +02:00
|
|
|
.middleware(simple::SayHi)
|
2019-03-10 19:19:50 -07:00
|
|
|
.service(web::resource("/login").to(|| {
|
|
|
|
"You are on /login. Go to src/redirect.rs to change this behavior."
|
|
|
|
}))
|
|
|
|
.service(
|
|
|
|
web::resource("/").to(|| {
|
|
|
|
"Hello, middleware! Check the console where the server is run."
|
|
|
|
}),
|
|
|
|
)
|
2019-03-09 18:03:09 -08:00
|
|
|
})
|
2019-03-10 19:19:50 -07:00
|
|
|
.bind("127.0.0.1:8080")?
|
|
|
|
.run()
|
2018-07-09 20:18:31 +02:00
|
|
|
}
|