Embed index.html and dedup people
This commit is contained in:
@@ -10,10 +10,7 @@
|
|||||||
|
|
||||||
<select id="person">
|
<select id="person">
|
||||||
<option selected disabled>Who is drawing?</option>
|
<option selected disabled>Who is drawing?</option>
|
||||||
<option value="Alice">Alice</option>
|
__OPTIONS__
|
||||||
<option value="Bob">Bob</option>
|
|
||||||
<option value="Carol">Carol</option>
|
|
||||||
<option value="Dave">Dave</option>
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<div id="result"></div>
|
<div id="result"></div>
|
||||||
@@ -28,7 +25,7 @@
|
|||||||
|
|
||||||
console.log(options);
|
console.log(options);
|
||||||
|
|
||||||
fetch("/secret-santa-api/", options)
|
fetch("api", options)
|
||||||
.then(response => response.text())
|
.then(response => response.text())
|
||||||
.then(text => {
|
.then(text => {
|
||||||
document.getElementById("result").textContent = `Your draw: ${text}`;
|
document.getElementById("result").textContent = `Your draw: ${text}`;
|
||||||
19
src/main.rs
19
src/main.rs
@@ -1,4 +1,8 @@
|
|||||||
use axum::{routing::post, Json, Router};
|
use axum::{
|
||||||
|
response::Html,
|
||||||
|
routing::{get, post},
|
||||||
|
Json, Router,
|
||||||
|
};
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
@@ -10,7 +14,9 @@ async fn main() {
|
|||||||
tracing_subscriber::fmt::init();
|
tracing_subscriber::fmt::init();
|
||||||
|
|
||||||
// build our application with some routes
|
// build our application with some routes
|
||||||
let app = Router::new().route("/secret-santa-api", post(input));
|
let app = Router::new()
|
||||||
|
.route("/", get(|| async { Html(INDEX_HTML.as_str()) }))
|
||||||
|
.route("/api", post(input));
|
||||||
|
|
||||||
// run it with hyper
|
// run it with hyper
|
||||||
let addr = SocketAddr::from(([127, 0, 0, 1], 3067));
|
let addr = SocketAddr::from(([127, 0, 0, 1], 3067));
|
||||||
@@ -20,6 +26,15 @@ async fn main() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static INDEX_HTML: Lazy<String> = Lazy::new(|| {
|
||||||
|
let content = include_str!("index.html");
|
||||||
|
let options: String = everyone()
|
||||||
|
.into_iter()
|
||||||
|
.map(|person| format!(r#"<option value="{person}">{person}</option>"#))
|
||||||
|
.collect();
|
||||||
|
content.replace("__OPTIONS__", &options)
|
||||||
|
});
|
||||||
|
|
||||||
static STATE: Lazy<Mutex<State>> = Lazy::new(Mutex::default);
|
static STATE: Lazy<Mutex<State>> = Lazy::new(Mutex::default);
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
|
|||||||
Reference in New Issue
Block a user