rearranged static files

This commit is contained in:
realaravinth
2021-05-29 12:22:31 +05:30
parent 417e008c27
commit c873d152c3
83 changed files with 49 additions and 44 deletions

View File

@@ -51,7 +51,7 @@ pub fn services(cfg: &mut web::ServiceConfig) {
}
#[derive(RustEmbed)]
#[folder = "docs/"]
#[folder = "static/openapi/"]
struct Asset;
pub fn handle_embedded_file(path: &str) -> HttpResponse {

View File

@@ -55,11 +55,11 @@ lazy_static! {
// pub static ref S: String = env::var("S").unwrap();
pub static ref FILES: FileMap = FileMap::new();
pub static ref JS: &'static str =
FILES.get("./static-assets/bundle/bundle.js").unwrap();
FILES.get("./static/cache/bundle/bundle.js").unwrap();
pub static ref CSS: &'static str =
FILES.get("./static-assets/bundle/bundle.css").unwrap();
FILES.get("./static/cache/bundle/bundle.css").unwrap();
pub static ref MOBILE_CSS: &'static str =
FILES.get("./static-assets/bundle/mobile.css").unwrap();
FILES.get("./static/cache/bundle/mobile.css").unwrap();
/// points to source files matching build commit
pub static ref SOURCE_FILES_OF_INSTANCE: String = {

View File

@@ -45,8 +45,8 @@ mod tests {
#[test]
fn filemap_works() {
let files = super::FileMap::new();
let css = files.get("./static-assets/bundle/bundle.css").unwrap();
let css = files.get("./static/cache/bundle/bundle.css").unwrap();
println!("{}", css);
assert!(css.contains("/static/bundle/bundle"));
assert!(css.contains("/assets/bundle/bundle"));
}
}

View File

@@ -25,7 +25,7 @@ use rust_embed::RustEmbed;
use crate::CACHE_AGE;
#[derive(RustEmbed)]
#[folder = "static/"]
#[folder = "assets/"]
struct Asset;
fn handle_assets(path: &str) -> HttpResponse {
@@ -47,7 +47,7 @@ fn handle_assets(path: &str) -> HttpResponse {
}
}
#[get("/static/{_:.*}")]
#[get("/assets/{_:.*}")]
pub async fn static_files(path: web::Path<String>) -> impl Responder {
handle_assets(&path.0)
}
@@ -55,7 +55,7 @@ pub async fn static_files(path: web::Path<String>) -> impl Responder {
#[derive(RustEmbed)]
#[folder = "static-assets/favicons/"]
#[folder = "static/favicons/"]
struct Favicons;
fn handle_favicons(path: &str) -> HttpResponse {
@@ -90,7 +90,6 @@ mod tests {
use super::*;
use crate::*;
use crate::tests::*;
#[actix_rt::test]
async fn static_assets_work() {
@@ -102,6 +101,18 @@ mod tests {
)
.await;
assert_eq!(resp.status(), StatusCode::OK);
let resp = test::call_service(
&mut app,
test::TestRequest::get().uri(
crate::FILES
.get("./static/cache/img/icon-trans.png")
.unwrap()
).to_request(),
)
.await;
assert_eq!(resp.status(), StatusCode::OK);
}
#[actix_rt::test]

View File

@@ -72,20 +72,12 @@ pub fn services(cfg: &mut web::ServiceConfig) {
mod test {
use actix_web::http::StatusCode;
use actix_web::test;
use actix_web::web::Bytes;
use crate::*;
#[actix_rt::test]
async fn captcha_widget_route_works() {
let mut app = test::init_service(
actix_web::App::new()
.wrap(get_identity_service())
.wrap(actix_middleware::NormalizePath::new(
actix_middleware::normalize::TrailingSlash::Trim,
))
.configure(crate::widget::services)
).await;
let mut app = get_app!().await;
let list_sitekey_resp = test::call_service(