add basic website (#71)
adds an index.html, and static file serving from `assets/`
This commit is contained in:
commit
3c77ce8308
8 changed files with 98 additions and 28 deletions
61
Cargo.lock
generated
61
Cargo.lock
generated
|
|
@ -214,6 +214,20 @@ dependencies = [
|
||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "axum-embed"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "077959a7f8cf438676af90b483304528eb7e16eadadb7f44e9ada4f9dceb9e62"
|
||||||
|
dependencies = [
|
||||||
|
"axum-core",
|
||||||
|
"chrono",
|
||||||
|
"http",
|
||||||
|
"mime_guess",
|
||||||
|
"rust-embed",
|
||||||
|
"tower-service",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "axum-extra"
|
name = "axum-extra"
|
||||||
version = "0.9.6"
|
version = "0.9.6"
|
||||||
|
|
@ -651,6 +665,7 @@ dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"atoi_radix10",
|
"atoi_radix10",
|
||||||
"axum",
|
"axum",
|
||||||
|
"axum-embed",
|
||||||
"axum-extra",
|
"axum-extra",
|
||||||
"axum-streams",
|
"axum-streams",
|
||||||
"bytes",
|
"bytes",
|
||||||
|
|
@ -660,6 +675,7 @@ dependencies = [
|
||||||
"headers",
|
"headers",
|
||||||
"image",
|
"image",
|
||||||
"rand",
|
"rand",
|
||||||
|
"rust-embed",
|
||||||
"serde",
|
"serde",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"test-case",
|
"test-case",
|
||||||
|
|
@ -1667,6 +1683,40 @@ version = "0.8.50"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "57397d16646700483b67d2dd6511d79318f9d057fdbd21a4066aeac8b41d310a"
|
checksum = "57397d16646700483b67d2dd6511d79318f9d057fdbd21a4066aeac8b41d310a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rust-embed"
|
||||||
|
version = "8.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fa66af4a4fdd5e7ebc276f115e895611a34739a9c1c01028383d612d550953c0"
|
||||||
|
dependencies = [
|
||||||
|
"rust-embed-impl",
|
||||||
|
"rust-embed-utils",
|
||||||
|
"walkdir",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rust-embed-impl"
|
||||||
|
version = "8.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6125dbc8867951125eec87294137f4e9c2c96566e61bf72c45095a7c77761478"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"rust-embed-utils",
|
||||||
|
"syn",
|
||||||
|
"walkdir",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rust-embed-utils"
|
||||||
|
version = "8.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2e5347777e9aacb56039b0e1f28785929a8a3b709e87482e7442c72e7c12529d"
|
||||||
|
dependencies = [
|
||||||
|
"sha2",
|
||||||
|
"walkdir",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc-demangle"
|
name = "rustc-demangle"
|
||||||
version = "0.1.24"
|
version = "0.1.24"
|
||||||
|
|
@ -1787,6 +1837,17 @@ dependencies = [
|
||||||
"digest",
|
"digest",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sha2"
|
||||||
|
version = "0.10.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"cpufeatures",
|
||||||
|
"digest",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sharded-slab"
|
name = "sharded-slab"
|
||||||
version = "0.1.7"
|
version = "0.1.7"
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ edition = "2021"
|
||||||
async-trait = "0.1.83"
|
async-trait = "0.1.83"
|
||||||
atoi_radix10 = { version = "0.0.1", optional = true }
|
atoi_radix10 = { version = "0.0.1", optional = true }
|
||||||
axum = { version = "0.7.7", features = ["ws"] }
|
axum = { version = "0.7.7", features = ["ws"] }
|
||||||
|
axum-embed = "0.1.0"
|
||||||
axum-extra = { version = "0.9.4", features = ["typed-header"] }
|
axum-extra = { version = "0.9.4", features = ["typed-header"] }
|
||||||
axum-streams = "0.19.0"
|
axum-streams = "0.19.0"
|
||||||
bytes = "1.6.0"
|
bytes = "1.6.0"
|
||||||
|
|
@ -15,6 +16,7 @@ futures = "0.3.31"
|
||||||
headers = "0.4.0"
|
headers = "0.4.0"
|
||||||
image = "0.25.2"
|
image = "0.25.2"
|
||||||
rand = "*"
|
rand = "*"
|
||||||
|
rust-embed = "8.5.0"
|
||||||
serde = { version = "1.0.210", features = ["derive"] }
|
serde = { version = "1.0.210", features = ["derive"] }
|
||||||
tokio = { version = "1.38", features = ["full"] }
|
tokio = { version = "1.38", features = ["full"] }
|
||||||
tokio-stream = "0.1.16"
|
tokio-stream = "0.1.16"
|
||||||
|
|
|
||||||
15
assets/index.html
Normal file
15
assets/index.html
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>Flurry</title>
|
||||||
|
<link href="css/style.css" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<img src="/imgstream?canvas=0" alt="The main pixelflut canvas">
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
|
|
@ -60,6 +60,7 @@
|
||||||
./Cargo.lock
|
./Cargo.lock
|
||||||
./Cargo.toml
|
./Cargo.toml
|
||||||
./src
|
./src
|
||||||
|
./assets
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -197,9 +197,14 @@ where
|
||||||
break 'outer;
|
break 'outer;
|
||||||
}
|
}
|
||||||
Err(err) if err.kind() == ErrorKind::UnexpectedEof => {
|
Err(err) if err.kind() == ErrorKind::UnexpectedEof => {
|
||||||
increment_counter(self.counter);
|
tracing::error!("Process socket got error: {err:?}");
|
||||||
return Ok(())},
|
increment_counter(self.counter);
|
||||||
Err(e) => return Err(e),
|
return Ok(())
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
tracing::error!("Process socket got error: {e:?}");
|
||||||
|
return Err(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
increment_counter(self.counter);
|
increment_counter(self.counter);
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ use axum::{
|
||||||
use axum_extra::TypedHeader;
|
use axum_extra::TypedHeader;
|
||||||
use axum_streams::StreamBodyAs;
|
use axum_streams::StreamBodyAs;
|
||||||
use futures::{never::Never, stream::repeat_with, Stream};
|
use futures::{never::Never, stream::repeat_with, Stream};
|
||||||
|
use rust_embed::RustEmbed;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
use tower_http::trace::{DefaultMakeSpan, TraceLayer};
|
use tower_http::trace::{DefaultMakeSpan, TraceLayer};
|
||||||
|
|
@ -21,14 +22,24 @@ use crate::{
|
||||||
AsyncResult,
|
AsyncResult,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[derive(RustEmbed, Clone)]
|
||||||
|
#[folder = "assets/"]
|
||||||
|
struct Assets;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct WebApiContext {
|
pub struct WebApiContext {
|
||||||
pub grids: Arc<[grid::Flut<u32>]>,
|
pub grids: Arc<[grid::Flut<u32>]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn serve(ctx: WebApiContext) -> AsyncResult<Never> {
|
pub async fn serve(ctx: WebApiContext) -> AsyncResult<Never> {
|
||||||
|
let assets = axum_embed::ServeEmbed::<Assets>::with_parameters(
|
||||||
|
Some("404.html".to_string()),
|
||||||
|
axum_embed::FallbackBehavior::NotFound,
|
||||||
|
Some("index.html".to_string()),
|
||||||
|
);
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route("/imgstream", any(image_stream))
|
.route("/imgstream", any(image_stream))
|
||||||
|
.nest_service("/", assets)
|
||||||
.with_state(ctx)
|
.with_state(ctx)
|
||||||
// logging middleware
|
// logging middleware
|
||||||
.layer(
|
.layer(
|
||||||
|
|
|
||||||
12
test.html
12
test.html
|
|
@ -1,12 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Test</title>
|
|
||||||
<script src="test.js"></script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>Test</h1>
|
|
||||||
<p>Test</p>
|
|
||||||
<img id="image"></img>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
13
test.js
13
test.js
|
|
@ -1,13 +0,0 @@
|
||||||
const ws = new WebSocket("ws://127.0.0.1:3000/imgstream?canvas=0");
|
|
||||||
console.log("Connecting");
|
|
||||||
ws.onopen = () => {
|
|
||||||
console.log("Connected");
|
|
||||||
}
|
|
||||||
ws.onmessage = (msg) => {
|
|
||||||
var reader = new FileReader();
|
|
||||||
reader.readAsDataURL(msg.data);
|
|
||||||
reader.onloadend = function() {
|
|
||||||
var base64data = reader.result;
|
|
||||||
document.getElementById("image").src = base64data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue