rss-reader/src/main.rs

62 lines
1.7 KiB
Rust
Executable File

extern crate diesel;
extern crate dotenv;
use actix_service::Service;
use actix_web::{App, HttpResponse, HttpServer};
use futures::future::{ok, Either};
mod auth;
mod database;
mod json_serialization;
mod models;
mod reader;
mod schema;
mod views;
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
env_logger::init();
HttpServer::new(|| {
let app = App::new()
.wrap_fn(|req, srv| {
let mut passed: bool;
let request_url: String = String::from(req.uri().path().clone());
log::info!("Request Url: {}", request_url);
if req.path().contains("/article/") {
match auth::process_token(&req) {
Ok(_token) => passed = true,
Err(_message) => passed = false,
}
} else {
log::warn!("No auth check done.");
passed = true;
}
if req.path().contains("user/create") {
passed = true;
}
log::info!("passed: {:?}", passed);
let end_result = match passed {
true => Either::Left(srv.call(req)),
false => Either::Right(ok(req.into_response(
HttpResponse::Unauthorized().finish().map_into_boxed_body(),
))),
};
async move {
let result = end_result.await?;
log::info!("{} -> {}", request_url, &result.status());
Ok(result)
}
})
.configure(views::views_factory);
return app;
})
.bind("127.0.0.1:8001")?
.run()
.await
}