summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock68
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs5
-rw-r--r--static/index.html12
4 files changed, 84 insertions, 2 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 4e29078..6d20b2a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -171,6 +171,7 @@ dependencies = [
"serde",
"serde_json",
"tokio",
+ "tower-http",
]
[[package]]
@@ -282,6 +283,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d"
[[package]]
+name = "futures-sink"
+version = "0.3.32"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893"
+
+[[package]]
name = "futures-task"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -407,6 +414,12 @@ dependencies = [
]
[[package]]
+name = "http-range-header"
+version = "0.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9171a2ea8a68358193d15dd5d70c1c10a2afc3e7e4c5bc92bc9f025cebd7359c"
+
+[[package]]
name = "httparse"
version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -561,6 +574,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
[[package]]
+name = "mime_guess"
+version = "2.0.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e"
+dependencies = [
+ "mime",
+ "unicase",
+]
+
+[[package]]
name = "mio"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1035,6 +1058,7 @@ version = "1.52.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "110a78583f19d5cdb2c5ccf321d1290344e71313c6c37d43520d386027d18386"
dependencies = [
+ "bytes",
"libc",
"mio",
"pin-project-lite",
@@ -1055,6 +1079,19 @@ dependencies = [
]
[[package]]
+name = "tokio-util"
+version = "0.7.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098"
+dependencies = [
+ "bytes",
+ "futures-core",
+ "futures-sink",
+ "pin-project-lite",
+ "tokio",
+]
+
+[[package]]
name = "tower"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1071,6 +1108,31 @@ dependencies = [
]
[[package]]
+name = "tower-http"
+version = "0.6.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "68d6fdd9f81c2819c9a8b0e0cd91660e7746a8e6ea2ba7c6b2b057985f6bcb51"
+dependencies = [
+ "bitflags",
+ "bytes",
+ "futures-core",
+ "futures-util",
+ "http",
+ "http-body",
+ "http-body-util",
+ "http-range-header",
+ "httpdate",
+ "mime",
+ "mime_guess",
+ "percent-encoding",
+ "pin-project-lite",
+ "tokio",
+ "tokio-util",
+ "tower-layer",
+ "tower-service",
+]
+
+[[package]]
name = "tower-layer"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1109,6 +1171,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40ce102ab67701b8526c123c1bab5cbe42d7040ccfd0f64af1a385808d2f43de"
[[package]]
+name = "unicase"
+version = "2.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dbc4bc3a9f746d862c45cb89d705aa10f187bb96c76001afab07a0d35ce60142"
+
+[[package]]
name = "unicode-ident"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index a9e44d5..72ae85f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,3 +12,4 @@ r2d2_sqlite = "0.34.0"
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.149"
tokio = { version = "1.52.2", features = ["macros", "rt-multi-thread"] }
+tower-http = { version = "0.6.10", features = ["fs"] }
diff --git a/src/main.rs b/src/main.rs
index 399a385..c1209bf 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -9,6 +9,7 @@ use axum::{
use routes::problem::{get_problems, create_problem};
use routes::user::create_user;
+use tower_http::services::ServeDir;
use crate::database::Database;
@@ -26,12 +27,14 @@ async fn main() {
let state = AppState {
database: database,
};
+
+ let static_files = ServeDir::new("./static");
let app = Router::new()
- .route("/", get(|| async {"Hello World!"}))
.route("/problem", get(get_problems))
.route("/problem", post(create_problem))
.route("/user", post(create_user))
+ .nest_service("/static", static_files)
.with_state(state);
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
diff --git a/static/index.html b/static/index.html
index d86f72d..37a831f 100644
--- a/static/index.html
+++ b/static/index.html
@@ -6,6 +6,15 @@
<title>Code Golf Leaderboard</title>
<link rel="stylesheet" href="default.css"/>
<script type="text/javascript">
+ async function fetch_problems() {
+ const response = await fetch("/problem");
+ if (!response.ok) {
+ console.log("ummm");
+ }
+
+ const result = await response.json();
+ console.log(result);
+ }
</script>
</head>
@@ -13,7 +22,8 @@
<div id="layout">
<div id="container">
<div id="holes">
-
+
+ <button onclick="fetch_problems()">Hello</button>
<h1>C&amp;! Code Golf Leaderboard</h1>
<p>In golf, the goal is to get a ball into a hole in as few swings as possible. The goal of code golf is similarly to solve a problem in as few bytes (of source code) as possible. The following is a list of programming challenges. Your task is to try and solve them in Python with as little code as possible measured in bytes.</p>