|
|
|
|
|
|
|
pub mod cache; |
|
pub mod config_parser; |
|
pub mod engines; |
|
pub mod handler; |
|
pub mod search_results_handler; |
|
pub mod server; |
|
|
|
use std::net::TcpListener; |
|
|
|
use crate::server::routes; |
|
|
|
use actix_files as fs; |
|
use actix_web::{dev::Server, middleware::Logger, web, App, HttpServer}; |
|
use config_parser::parser::Config; |
|
use handlebars::Handlebars; |
|
use handler::public_path_handler::handle_different_public_path; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn run(listener: TcpListener, config: Config) -> std::io::Result<Server> { |
|
let mut handlebars: Handlebars = Handlebars::new(); |
|
|
|
let public_folder_path: String = handle_different_public_path()?; |
|
|
|
handlebars |
|
.register_templates_directory(".html", format!("{}/templates", public_folder_path)) |
|
.unwrap(); |
|
|
|
let handlebars_ref: web::Data<Handlebars> = web::Data::new(handlebars); |
|
|
|
let server = HttpServer::new(move || { |
|
App::new() |
|
.app_data(handlebars_ref.clone()) |
|
.app_data(web::Data::new(config.clone())) |
|
.wrap(Logger::default()) |
|
|
|
.service( |
|
fs::Files::new("/static", format!("{}/static", public_folder_path)) |
|
.show_files_listing(), |
|
) |
|
.service( |
|
fs::Files::new("/images", format!("{}/images", public_folder_path)) |
|
.show_files_listing(), |
|
) |
|
.service(routes::robots_data) |
|
.service(routes::index) |
|
.service(routes::search) |
|
.service(routes::about) |
|
.service(routes::settings) |
|
.default_service(web::route().to(routes::not_found)) |
|
}) |
|
|
|
.listen(listener)? |
|
.run(); |
|
Ok(server) |
|
} |
|
|