Spaces:
Running
Running
neon_arch commited on
Commit ·
ca1c72c
1
Parent(s): c1a5b70
♻️ refactor: remove handlebar related code & add the templates module (#302)
Browse files- src/lib.rs +1 -10
src/lib.rs
CHANGED
|
@@ -12,6 +12,7 @@ pub mod handler;
|
|
| 12 |
pub mod models;
|
| 13 |
pub mod results;
|
| 14 |
pub mod server;
|
|
|
|
| 15 |
|
| 16 |
use std::net::TcpListener;
|
| 17 |
|
|
@@ -23,7 +24,6 @@ use actix_governor::{Governor, GovernorConfigBuilder};
|
|
| 23 |
use actix_web::{dev::Server, http::header, middleware::Logger, web, App, HttpServer};
|
| 24 |
use cache::cacher::{Cache, SharedCache};
|
| 25 |
use config::parser::Config;
|
| 26 |
-
use handlebars::Handlebars;
|
| 27 |
use handler::paths::{file_path, FileType};
|
| 28 |
|
| 29 |
/// Runs the web server on the provided TCP listener and returns a `Server` instance.
|
|
@@ -48,16 +48,8 @@ use handler::paths::{file_path, FileType};
|
|
| 48 |
/// let server = run(listener,config,cache).expect("Failed to start server");
|
| 49 |
/// ```
|
| 50 |
pub fn run(listener: TcpListener, config: Config, cache: Cache) -> std::io::Result<Server> {
|
| 51 |
-
let mut handlebars: Handlebars<'_> = Handlebars::new();
|
| 52 |
-
|
| 53 |
let public_folder_path: &str = file_path(FileType::Theme)?;
|
| 54 |
|
| 55 |
-
handlebars
|
| 56 |
-
.register_templates_directory(".html", format!("{}/templates", public_folder_path))
|
| 57 |
-
.unwrap();
|
| 58 |
-
|
| 59 |
-
let handlebars_ref: web::Data<Handlebars<'_>> = web::Data::new(handlebars);
|
| 60 |
-
|
| 61 |
let cloned_config_threads_opt: u8 = config.threads;
|
| 62 |
|
| 63 |
let cache = web::Data::new(SharedCache::new(cache));
|
|
@@ -75,7 +67,6 @@ pub fn run(listener: TcpListener, config: Config, cache: Cache) -> std::io::Resu
|
|
| 75 |
|
| 76 |
App::new()
|
| 77 |
.wrap(Logger::default()) // added logging middleware for logging.
|
| 78 |
-
.app_data(handlebars_ref.clone())
|
| 79 |
.app_data(web::Data::new(config.clone()))
|
| 80 |
.app_data(cache.clone())
|
| 81 |
.wrap(cors)
|
|
|
|
| 12 |
pub mod models;
|
| 13 |
pub mod results;
|
| 14 |
pub mod server;
|
| 15 |
+
pub mod templates;
|
| 16 |
|
| 17 |
use std::net::TcpListener;
|
| 18 |
|
|
|
|
| 24 |
use actix_web::{dev::Server, http::header, middleware::Logger, web, App, HttpServer};
|
| 25 |
use cache::cacher::{Cache, SharedCache};
|
| 26 |
use config::parser::Config;
|
|
|
|
| 27 |
use handler::paths::{file_path, FileType};
|
| 28 |
|
| 29 |
/// Runs the web server on the provided TCP listener and returns a `Server` instance.
|
|
|
|
| 48 |
/// let server = run(listener,config,cache).expect("Failed to start server");
|
| 49 |
/// ```
|
| 50 |
pub fn run(listener: TcpListener, config: Config, cache: Cache) -> std::io::Result<Server> {
|
|
|
|
|
|
|
| 51 |
let public_folder_path: &str = file_path(FileType::Theme)?;
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
let cloned_config_threads_opt: u8 = config.threads;
|
| 54 |
|
| 55 |
let cache = web::Data::new(SharedCache::new(cache));
|
|
|
|
| 67 |
|
| 68 |
App::new()
|
| 69 |
.wrap(Logger::default()) // added logging middleware for logging.
|
|
|
|
| 70 |
.app_data(web::Data::new(config.clone()))
|
| 71 |
.app_data(cache.clone())
|
| 72 |
.wrap(cors)
|