0
0
mirror of https://github.com/neon-mmd/websurfx.git synced 2024-11-22 05:58:21 -05:00

♻️ refactor: remove handlebar related code & add the templates module (#302)

This commit is contained in:
neon_arch 2023-11-18 21:27:49 +03:00
parent c1a5b7086a
commit ca1c72c3dc

View File

@ -12,6 +12,7 @@ pub mod handler;
pub mod models; pub mod models;
pub mod results; pub mod results;
pub mod server; pub mod server;
pub mod templates;
use std::net::TcpListener; use std::net::TcpListener;
@ -23,7 +24,6 @@ use actix_governor::{Governor, GovernorConfigBuilder};
use actix_web::{dev::Server, http::header, middleware::Logger, web, App, HttpServer}; use actix_web::{dev::Server, http::header, middleware::Logger, web, App, HttpServer};
use cache::cacher::{Cache, SharedCache}; use cache::cacher::{Cache, SharedCache};
use config::parser::Config; use config::parser::Config;
use handlebars::Handlebars;
use handler::paths::{file_path, FileType}; use handler::paths::{file_path, FileType};
/// Runs the web server on the provided TCP listener and returns a `Server` instance. /// Runs the web server on the provided TCP listener and returns a `Server` instance.
@ -48,16 +48,8 @@ use handler::paths::{file_path, FileType};
/// let server = run(listener,config,cache).expect("Failed to start server"); /// let server = run(listener,config,cache).expect("Failed to start server");
/// ``` /// ```
pub fn run(listener: TcpListener, config: Config, cache: Cache) -> std::io::Result<Server> { pub fn run(listener: TcpListener, config: Config, cache: Cache) -> std::io::Result<Server> {
let mut handlebars: Handlebars<'_> = Handlebars::new();
let public_folder_path: &str = file_path(FileType::Theme)?; let public_folder_path: &str = file_path(FileType::Theme)?;
handlebars
.register_templates_directory(".html", format!("{}/templates", public_folder_path))
.unwrap();
let handlebars_ref: web::Data<Handlebars<'_>> = web::Data::new(handlebars);
let cloned_config_threads_opt: u8 = config.threads; let cloned_config_threads_opt: u8 = config.threads;
let cache = web::Data::new(SharedCache::new(cache)); let cache = web::Data::new(SharedCache::new(cache));
@ -75,7 +67,6 @@ pub fn run(listener: TcpListener, config: Config, cache: Cache) -> std::io::Resu
App::new() App::new()
.wrap(Logger::default()) // added logging middleware for logging. .wrap(Logger::default()) // added logging middleware for logging.
.app_data(handlebars_ref.clone())
.app_data(web::Data::new(config.clone())) .app_data(web::Data::new(config.clone()))
.app_data(cache.clone()) .app_data(cache.clone())
.wrap(cors) .wrap(cors)