Merge pull request #26 from itsscb/feature

feat: performance improvements
This commit is contained in:
itsscb 2024-09-03 12:24:29 +02:00 committed by GitHub
commit aee0fd1400
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 134 additions and 4 deletions

88
Cargo.lock generated
View File

@ -17,6 +17,12 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "adler2"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
[[package]]
name = "aho-corasick"
version = "1.1.3"
@ -26,6 +32,21 @@ dependencies = [
"memchr",
]
[[package]]
name = "alloc-no-stdlib"
version = "2.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3"
[[package]]
name = "alloc-stdlib"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94fb8275041c72129eb51b7d0322c29b8387a0386127718b096429201a5d6ece"
dependencies = [
"alloc-no-stdlib",
]
[[package]]
name = "android-tzdata"
version = "0.1.1"
@ -59,6 +80,20 @@ version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d301b3b94cb4b2f23d7917810addbbaff90738e0ca2be692bd027e70d7e0330c"
[[package]]
name = "async-compression"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86a9249d1447a85f95810c620abea82e001fe58a31713fcce614caf52499f905"
dependencies = [
"brotli",
"flate2",
"futures-core",
"memchr",
"pin-project-lite",
"tokio",
]
[[package]]
name = "async-stream"
version = "0.3.5"
@ -208,7 +243,7 @@ dependencies = [
"cc",
"cfg-if",
"libc",
"miniz_oxide",
"miniz_oxide 0.7.4",
"object",
"rustc-demangle",
]
@ -246,6 +281,27 @@ version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cfa8873f51c92e232f9bac4065cddef41b714152812bfc5f7672ba16d6ef8cd9"
[[package]]
name = "brotli"
version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d640d25bc63c50fb1f0b545ffd80207d2e10a4c965530809b40ba3386825c391"
dependencies = [
"alloc-no-stdlib",
"alloc-stdlib",
"brotli-decompressor",
]
[[package]]
name = "brotli-decompressor"
version = "2.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e2e4afe60d7dd600fdd3de8d0f08c2b7ec039712e3b6137ff98b7004e82de4f"
dependencies = [
"alloc-no-stdlib",
"alloc-stdlib",
]
[[package]]
name = "bumpalo"
version = "3.16.0"
@ -330,6 +386,15 @@ version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
[[package]]
name = "crc32fast"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3"
dependencies = [
"cfg-if",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.13"
@ -433,6 +498,16 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "flate2"
version = "1.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "324a1be68054ef05ad64b861cc9eaf1d623d2d8cb25b4bf2cb9cdd902b4bf253"
dependencies = [
"crc32fast",
"miniz_oxide 0.8.0",
]
[[package]]
name = "fnv"
version = "1.0.7"
@ -1302,6 +1377,15 @@ dependencies = [
"adler",
]
[[package]]
name = "miniz_oxide"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1"
dependencies = [
"adler2",
]
[[package]]
name = "mio"
version = "0.8.11"
@ -2258,8 +2342,10 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e9cd434a998747dd2c4276bc96ee2e0c7a2eadf3cae88e52be55a05fa9053f5"
dependencies = [
"async-compression",
"bitflags 2.6.0",
"bytes",
"futures-core",
"futures-util",
"http 1.1.0",
"http-body 1.0.1",

View File

@ -9,7 +9,7 @@ http = "1.1.0"
rand = "0.8.5"
shuttle-axum = "0.47.0"
shuttle-runtime = "0.47.0"
tower-http = { version = "0.5.2", features = ["fs", "cors"] }
tower-http = { version = "0.5.2", features = ["compression-br", "compression-gzip", "cors", "fs"] }
tracing = "0.1.40"

View File

@ -1,7 +1,7 @@
[[hooks]]
stage = "build"
command = "tailwindcss"
command_arguments = ["-i","input.css","-o","public/styles.css"]
command_arguments = ["-i","input.css","-o","public/styles.css","--minify"]
[serve]
address = "0.0.0.0"

View File

@ -6,6 +6,49 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Author: itsscb, Description: Guess a random word with five letters">
<title>wordl</title>
<style>
.bg-black {
--tw-bg-opacity: 1;
background-color: rgb(0 0 0 / var(--tw-bg-opacity));
}
.text-white {
--tw-text-opacity: 1;
color: rgb(255 255 255 / var(--tw-text-opacity));
}
.pt-12 {
padding-top: 3rem;
}
.w-16 {
width: 4rem;
}
.h-16 {
height: 4rem;
}
.h-\[90vh\] {
height: 90vh;
}
.flex {
display: flex;
}
.flex-col {
flex-direction: column;
}
.justify-center {
justify-content: center;
}
.items-center {
align-items: center;
}
</style>
<link data-trunk href="./public/styles.css" rel="css">
<link data-trunk rel="copy-file" href="public/robots.txt" data-target-path="/" />
<!-- <link data-trunk href="./assets/favicon.ico" rel="icon" type="image/x-icon"> -->

View File

@ -10,6 +10,7 @@ use http::Method;
use rand::seq::SliceRandom;
use tower_http::cors::{Any, CorsLayer};
use tower_http::services::ServeDir;
use tower_http::compression::CompressionLayer;
use tracing::info;
#[shuttle_runtime::main]
@ -21,7 +22,7 @@ async fn main() -> shuttle_axum::ShuttleAxum {
.allow_headers(Any);
let router = Router::new()
.nest_service("/", ServeDir::new("frontend/dist"))
.nest_service("/", ServeDir::new("frontend/dist").precompressed_br().precompressed_gzip()).layer(CompressionLayer::new())
.route("/word", get(word))
.layer(middleware::from_fn(log_ip))
.layer(cors);