diff --git a/app/build.sh b/app/build.sh index dde5d3f..780f16e 100755 --- a/app/build.sh +++ b/app/build.sh @@ -14,4 +14,4 @@ fi wasm-pack build --target web --release -gzip -9 -f pkg/lldap_app_bg.wasm +gzip -9 -k -f pkg/lldap_app_bg.wasm diff --git a/app/static/main.js b/app/static/main.js index 4dc13f5..cbaa7a8 100644 --- a/app/static/main.js +++ b/app/static/main.js @@ -1,6 +1,10 @@ import init, { run_app } from '/pkg/lldap_app.js'; async function main() { - await init('/pkg/lldap_app_bg.wasm'); - run_app(); + if(navigator.userAgent.indexOf('AppleWebKit') != -1) { + await init('/pkg/lldap_app_bg.wasm'); + } else { + await init('/pkg/lldap_app_bg.wasm.gz'); + } + run_app(); } main() diff --git a/server/src/infra/tcp_server.rs b/server/src/infra/tcp_server.rs index c20358d..43f65ea 100644 --- a/server/src/infra/tcp_server.rs +++ b/server/src/infra/tcp_server.rs @@ -16,7 +16,7 @@ use actix_files::{Files, NamedFile}; use actix_http::{header, HttpServiceBuilder}; use actix_server::ServerBuilder; use actix_service::map_config; -use actix_web::{dev::AppConfig, guard, middleware, web, App, HttpResponse, Responder}; +use actix_web::{dev::AppConfig, guard, web, App, HttpResponse, Responder}; use anyhow::{Context, Result}; use hmac::Hmac; use sha2::Sha512; @@ -68,6 +68,10 @@ pub(crate) fn error_to_http_response(error: TcpError) -> HttpResponse { } async fn wasm_handler() -> actix_web::Result { + Ok(actix_files::NamedFile::open_async("./app/pkg/lldap_app_bg.wasm").await?) +} + +async fn wasm_handler_compressed() -> actix_web::Result { Ok( actix_files::NamedFile::open_async("./app/pkg/lldap_app_bg.wasm.gz") .await? @@ -110,12 +114,9 @@ fn http_config( .configure(super::graphql::api::configure_endpoint::), ) .service( - web::resource("/pkg/lldap_app_bg.wasm").route( - web::route() - .wrap(middleware::Compress::default()) - .to(wasm_handler), - ), + web::resource("/pkg/lldap_app_bg.wasm.gz").route(web::route().to(wasm_handler_compressed)), ) + .service(web::resource("/pkg/lldap_app_bg.wasm").route(web::route().to(wasm_handler))) // Serve the /pkg path with the compiled WASM app. .service(Files::new("/pkg", "./app/pkg")) // Serve static files