Spaces:
Runtime error
Runtime error
neon_arch
commited on
Commit
β’
dc3308c
1
Parent(s):
211f170
chore: rename from theme to public
Browse files
src/handler/mod.rs
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
pub mod public_path_handler;
|
src/{theme_handler/theme_path_handler.rs β handler/public_path_handler.rs}
RENAMED
@@ -5,7 +5,7 @@ use std::io::Error;
|
|
5 |
use std::path::Path;
|
6 |
|
7 |
// ------- Constants --------
|
8 |
-
static
|
9 |
|
10 |
/// A function which returns an appropriate theme directory path checking if the theme
|
11 |
/// directory exists on that path.
|
@@ -17,11 +17,11 @@ static THEME_DIRECTORY_NAME: &str = "public";
|
|
17 |
/// 1. `/opt/websurfx` if it not present here then it fallbacks to the next one (2)
|
18 |
/// 2. Under project folder ( or codebase in other words) if it is not present
|
19 |
/// here then it returns an error as mentioned above.
|
20 |
-
pub fn
|
21 |
-
if Path::new(format!("/opt/websurfx/{}/",
|
22 |
-
Ok(format!("/opt/websurfx/{}",
|
23 |
-
} else if Path::new(format!("./{}/",
|
24 |
-
Ok(format!("./{}",
|
25 |
} else {
|
26 |
Err(Error::new(
|
27 |
std::io::ErrorKind::NotFound,
|
|
|
5 |
use std::path::Path;
|
6 |
|
7 |
// ------- Constants --------
|
8 |
+
static PUBLIC_DIRECTORY_NAME: &str = "public";
|
9 |
|
10 |
/// A function which returns an appropriate theme directory path checking if the theme
|
11 |
/// directory exists on that path.
|
|
|
17 |
/// 1. `/opt/websurfx` if it not present here then it fallbacks to the next one (2)
|
18 |
/// 2. Under project folder ( or codebase in other words) if it is not present
|
19 |
/// here then it returns an error as mentioned above.
|
20 |
+
pub fn handle_different_public_path() -> Result<String, Error> {
|
21 |
+
if Path::new(format!("/opt/websurfx/{}/", PUBLIC_DIRECTORY_NAME).as_str()).exists() {
|
22 |
+
Ok(format!("/opt/websurfx/{}", PUBLIC_DIRECTORY_NAME))
|
23 |
+
} else if Path::new(format!("./{}/", PUBLIC_DIRECTORY_NAME).as_str()).exists() {
|
24 |
+
Ok(format!("./{}", PUBLIC_DIRECTORY_NAME))
|
25 |
} else {
|
26 |
Err(Error::new(
|
27 |
std::io::ErrorKind::NotFound,
|
src/lib.rs
CHANGED
@@ -4,9 +4,9 @@
|
|
4 |
pub mod cache;
|
5 |
pub mod config_parser;
|
6 |
pub mod engines;
|
|
|
7 |
pub mod search_results_handler;
|
8 |
pub mod server;
|
9 |
-
pub mod theme_handler;
|
10 |
|
11 |
use std::net::TcpListener;
|
12 |
|
@@ -16,7 +16,7 @@ use actix_files as fs;
|
|
16 |
use actix_web::{dev::Server, middleware::Logger, web, App, HttpServer};
|
17 |
use config_parser::parser::Config;
|
18 |
use handlebars::Handlebars;
|
19 |
-
use
|
20 |
|
21 |
/// Runs the web server on the provided TCP listener and returns a `Server` instance.
|
22 |
///
|
@@ -41,10 +41,10 @@ use theme_handler::theme_path_handler::handle_different_theme_path;
|
|
41 |
pub fn run(listener: TcpListener, config: Config) -> std::io::Result<Server> {
|
42 |
let mut handlebars: Handlebars = Handlebars::new();
|
43 |
|
44 |
-
let
|
45 |
|
46 |
handlebars
|
47 |
-
.register_templates_directory(".html", format!("{}/templates",
|
48 |
.unwrap();
|
49 |
|
50 |
let handlebars_ref: web::Data<Handlebars> = web::Data::new(handlebars);
|
@@ -56,11 +56,11 @@ pub fn run(listener: TcpListener, config: Config) -> std::io::Result<Server> {
|
|
56 |
.wrap(Logger::default()) // added logging middleware for logging.
|
57 |
// Serve images and static files (css and js files).
|
58 |
.service(
|
59 |
-
fs::Files::new("/static", format!("{}/static",
|
60 |
.show_files_listing(),
|
61 |
)
|
62 |
.service(
|
63 |
-
fs::Files::new("/images", format!("{}/images",
|
64 |
.show_files_listing(),
|
65 |
)
|
66 |
.service(routes::robots_data) // robots.txt
|
|
|
4 |
pub mod cache;
|
5 |
pub mod config_parser;
|
6 |
pub mod engines;
|
7 |
+
pub mod handler;
|
8 |
pub mod search_results_handler;
|
9 |
pub mod server;
|
|
|
10 |
|
11 |
use std::net::TcpListener;
|
12 |
|
|
|
16 |
use actix_web::{dev::Server, middleware::Logger, web, App, HttpServer};
|
17 |
use config_parser::parser::Config;
|
18 |
use handlebars::Handlebars;
|
19 |
+
use handler::public_path_handler::handle_different_public_path;
|
20 |
|
21 |
/// Runs the web server on the provided TCP listener and returns a `Server` instance.
|
22 |
///
|
|
|
41 |
pub fn run(listener: TcpListener, config: Config) -> std::io::Result<Server> {
|
42 |
let mut handlebars: Handlebars = Handlebars::new();
|
43 |
|
44 |
+
let public_folder_path: String = handle_different_public_path()?;
|
45 |
|
46 |
handlebars
|
47 |
+
.register_templates_directory(".html", format!("{}/templates", public_folder_path))
|
48 |
.unwrap();
|
49 |
|
50 |
let handlebars_ref: web::Data<Handlebars> = web::Data::new(handlebars);
|
|
|
56 |
.wrap(Logger::default()) // added logging middleware for logging.
|
57 |
// Serve images and static files (css and js files).
|
58 |
.service(
|
59 |
+
fs::Files::new("/static", format!("{}/static", public_folder_path))
|
60 |
.show_files_listing(),
|
61 |
)
|
62 |
.service(
|
63 |
+
fs::Files::new("/images", format!("{}/images", public_folder_path))
|
64 |
.show_files_listing(),
|
65 |
)
|
66 |
.service(routes::robots_data) // robots.txt
|
src/server/routes.rs
CHANGED
@@ -7,8 +7,8 @@ use std::fs::read_to_string;
|
|
7 |
use crate::{
|
8 |
cache::cacher::RedisCache,
|
9 |
config_parser::parser::Config,
|
|
|
10 |
search_results_handler::{aggregation_models::SearchResults, aggregator::aggregate},
|
11 |
-
theme_handler::theme_path_handler::handle_different_theme_path,
|
12 |
};
|
13 |
use actix_web::{get, web, HttpRequest, HttpResponse};
|
14 |
use handlebars::Handlebars;
|
@@ -148,7 +148,7 @@ pub async fn search(
|
|
148 |
#[get("/robots.txt")]
|
149 |
pub async fn robots_data(_req: HttpRequest) -> Result<HttpResponse, Box<dyn std::error::Error>> {
|
150 |
let page_content: String =
|
151 |
-
read_to_string(format!("{}/robots.txt",
|
152 |
Ok(HttpResponse::Ok()
|
153 |
.content_type("text/plain; charset=ascii")
|
154 |
.body(page_content))
|
|
|
7 |
use crate::{
|
8 |
cache::cacher::RedisCache,
|
9 |
config_parser::parser::Config,
|
10 |
+
handler::public_path_handler::handle_different_public_path,
|
11 |
search_results_handler::{aggregation_models::SearchResults, aggregator::aggregate},
|
|
|
12 |
};
|
13 |
use actix_web::{get, web, HttpRequest, HttpResponse};
|
14 |
use handlebars::Handlebars;
|
|
|
148 |
#[get("/robots.txt")]
|
149 |
pub async fn robots_data(_req: HttpRequest) -> Result<HttpResponse, Box<dyn std::error::Error>> {
|
150 |
let page_content: String =
|
151 |
+
read_to_string(format!("{}/robots.txt", handle_different_public_path()?))?;
|
152 |
Ok(HttpResponse::Ok()
|
153 |
.content_type("text/plain; charset=ascii")
|
154 |
.body(page_content))
|
src/theme_handler/mod.rs
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
pub mod theme_path_handler;
|
|
|
|