ft/adds word endpoint

This commit is contained in:
itsscb 2024-06-23 23:54:43 +02:00
parent a18aa55240
commit ed5d6431ba
2 changed files with 10 additions and 2 deletions

View File

@ -5,6 +5,7 @@ edition = "2021"
[dependencies] [dependencies]
axum = "0.7.4" axum = "0.7.4"
rand = "0.8.5"
shuttle-axum = "0.45.0" shuttle-axum = "0.45.0"
shuttle-runtime = "0.45.0" shuttle-runtime = "0.45.0"
tokio = "1.28.2" tokio = "1.28.2"

View File

@ -1,15 +1,22 @@
use axum::Router; use axum::{routing::get, Router};
use rand::seq::SliceRandom;
use tower_http::services::ServeDir; use tower_http::services::ServeDir;
#[shuttle_runtime::main] #[shuttle_runtime::main]
async fn main() -> shuttle_axum::ShuttleAxum { async fn main() -> shuttle_axum::ShuttleAxum {
let router = Router::new() let router = Router::new()
// .route("/", get(hello_world)) // .route("/", get(hello_world))
.nest_service("/", ServeDir::new("frontend/dist")); .nest_service("/", ServeDir::new("frontend/dist"))
.route("/word", get(word));
Ok(router.into()) Ok(router.into())
} }
async fn word() -> String {
let mut rng = rand::thread_rng();
WORDS.choose(&mut rng).unwrap().to_string()
}
static WORDS: &[&str; 5921] = &[ static WORDS: &[&str; 5921] = &[
"aalen", "Aales", "aalst", "aalte", "Aarau", "Aaron", "Aasee", "Aases", "Abart", "abbat", "aalen", "Aales", "aalst", "aalte", "Aarau", "Aaron", "Aasee", "Aases", "Abart", "abbat",
"Abbau", "Abbey", "abbog", "Abdul", "Abeba", "Abels", "Abend", "abgab", "Abgas", "abhob", "Abbau", "Abbey", "abbog", "Abdul", "Abeba", "Abels", "Abend", "abgab", "Abgas", "abhob",