replace commandline arguments with config.lua & add support for changing themes & coloschemes

This commit is contained in:
neon_arch 2023-04-30 18:16:08 +03:00
parent fe8f5dee43
commit 137c62ed5f
17 changed files with 209 additions and 228 deletions

View file

@ -1,21 +1,22 @@
//! This main library module provides the functionality to provide and handle the Tcp server
//! and register all the routes for the `websurfx` meta search engine website.
pub mod config_parser;
pub mod engines;
pub mod server;
pub mod search_results_handler;
pub mod server;
use std::net::TcpListener;
use crate::server::routes;
use actix_files as fs;
use actix_web::{middleware::Logger, web, App, HttpServer, dev::Server};
use actix_web::{dev::Server, middleware::Logger, web, App, HttpServer};
use config_parser::parser::Config;
use handlebars::Handlebars;
/// Runs the web server on the provided TCP listener and returns a `Server` instance.
///
///
/// # Arguments
///
/// * `listener` - A `TcpListener` instance representing the address and port to listen on.
@ -25,7 +26,7 @@ use handlebars::Handlebars;
/// Returns a `Result` containing a `Server` instance on success, or an `std::io::Error` on failure.
///
/// # Example
///
///
/// ```rust
/// use std::net::TcpListener;
/// use websurfx::run;
@ -33,7 +34,7 @@ use handlebars::Handlebars;
/// let listener = TcpListener::bind("127.0.0.1:8080").expect("Failed to bind address");
/// let server = run(listener).expect("Failed to start server");
/// ```
pub fn run(listener: TcpListener) -> std::io::Result<Server> {
pub fn run(listener: TcpListener, config: Config) -> std::io::Result<Server> {
let mut handlebars: Handlebars = Handlebars::new();
handlebars
@ -45,6 +46,7 @@ pub fn run(listener: TcpListener) -> std::io::Result<Server> {
let server = HttpServer::new(move || {
App::new()
.app_data(handlebars_ref.clone())
.app_data(web::Data::new(config.clone()))
.wrap(Logger::default()) // added logging middleware for logging.
// Serve images and static files (css and js files).
.service(fs::Files::new("/static", "./public/static").show_files_listing())