|
|
@@ -1,19 +1,36 @@
|
|
|
use actix_web::{HttpResponse, web, get};
|
|
|
-use std::sync::Mutex;
|
|
|
-use crate::users::User;
|
|
|
+use std::{fs, sync::Mutex, borrow::Cow};
|
|
|
+use crate::{
|
|
|
+ users::User,
|
|
|
+ environment::Environment
|
|
|
+};
|
|
|
|
|
|
const HTML: &str = include_str!("../../ui/build.html");
|
|
|
|
|
|
#[get("/")]
|
|
|
-pub async fn route(users: web::Data<Mutex<Vec<User>>>) -> HttpResponse {
|
|
|
- if users.lock().unwrap().is_empty() {
|
|
|
- let updated_html = HTML.replacen(
|
|
|
+pub async fn route(
|
|
|
+ users: web::Data<Mutex<Vec<User>>>,
|
|
|
+ app_env: web::Data<Environment>
|
|
|
+) -> HttpResponse {
|
|
|
+ let html: Cow<str> = match **app_env {
|
|
|
+ Environment::Development => {
|
|
|
+ Cow::Owned(
|
|
|
+ fs::read_to_string("./ui/build.html")
|
|
|
+ .expect("Failed to read build file")
|
|
|
+ )
|
|
|
+ },
|
|
|
+ Environment::Production => Cow::Borrowed(HTML)
|
|
|
+ };
|
|
|
+
|
|
|
+ let final_html = if users.lock().unwrap().is_empty() {
|
|
|
+ Cow::Owned(html.replacen(
|
|
|
"window.adminExists=\"true\";",
|
|
|
"window.adminExists=\"false\";",
|
|
|
1
|
|
|
- );
|
|
|
- HttpResponse::Ok().body(updated_html)
|
|
|
+ ))
|
|
|
} else {
|
|
|
- HttpResponse::Ok().body(HTML)
|
|
|
- }
|
|
|
+ html
|
|
|
+ };
|
|
|
+
|
|
|
+ HttpResponse::Ok().body(final_html)
|
|
|
}
|