summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-02-11 10:29:02 +0100
committermetamuffin <metamuffin@disroot.org>2023-02-11 10:29:02 +0100
commit9dfc929b709d4187dc307f68a42fa058eda7a4c1 (patch)
treed9c56d3a2ccabd7183d539f3b2b349be62530aad /server
parent89f9f9e1c3a29ba16d53227786dfba18587f9fa7 (diff)
downloadkeks-meet-9dfc929b709d4187dc307f68a42fa058eda7a4c1.tar
keks-meet-9dfc929b709d4187dc307f68a42fa058eda7a4c1.tar.bz2
keks-meet-9dfc929b709d4187dc307f68a42fa058eda7a4c1.tar.zst
standalone binary
Diffstat (limited to 'server')
-rw-r--r--server/Cargo.toml7
-rw-r--r--server/src/assets.rs37
-rw-r--r--server/src/main.rs9
3 files changed, 48 insertions, 5 deletions
diff --git a/server/Cargo.toml b/server/Cargo.toml
index e2b0506..907b8c4 100644
--- a/server/Cargo.toml
+++ b/server/Cargo.toml
@@ -12,4 +12,9 @@ futures-util = "0.3.26"
listenfd = "1.0.0"
hyper = "0.14.24"
serde = { version = "1.0.152", features = ["derive"] }
-serde_json = "*"
+serde_json = "1.0.93"
+include_dir = "0.7.3"
+
+[features]
+default = ["standalone"]
+standalone = []
diff --git a/server/src/assets.rs b/server/src/assets.rs
new file mode 100644
index 0000000..068bc0c
--- /dev/null
+++ b/server/src/assets.rs
@@ -0,0 +1,37 @@
+#[cfg(not(feature = "standalone"))]
+#[macro_export]
+macro_rules! s_file {
+ ($path: literal) => {
+ warp::fs::file($path)
+ };
+}
+
+#[cfg(not(feature = "standalone"))]
+#[macro_export]
+macro_rules! s_asset_dir {
+ () => {
+ warp::fs::dir("client-web/public/assets")
+ };
+}
+
+#[cfg(feature = "standalone")]
+#[macro_export]
+macro_rules! s_file {
+ ($path: literal) => {
+ warp::get().map(|| include_str!(concat!("../../", $path)))
+ };
+}
+
+#[cfg(feature = "standalone")]
+#[macro_export]
+macro_rules! s_asset_dir {
+ () => {{
+ use include_dir::{include_dir, Dir};
+ const DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/../client-web/public/assets");
+ warp::path::tail().and_then(|t: warp::path::Tail| async move {
+ DIR.get_file(t.as_str())
+ .map(|f| f.contents_utf8().unwrap())
+ .ok_or(warp::reject::not_found())
+ })
+ }};
+}
diff --git a/server/src/main.rs b/server/src/main.rs
index 413f23a..518ea99 100644
--- a/server/src/main.rs
+++ b/server/src/main.rs
@@ -3,6 +3,7 @@
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2022 metamuffin <metamuffin@disroot.org>
*/
+pub mod assets;
pub mod protocol;
pub mod room;
@@ -41,10 +42,10 @@ async fn run() {
.and(warp::ws())
.map(signaling_connect);
- let index: _ = warp::path!().and(warp::fs::file("../client-web/public/start.html"));
- let room: _ = warp::path!("room").and(warp::fs::file("../client-web/public/app.html"));
- let assets: _ = warp::path("assets").and(warp::fs::dir("../client-web/public/assets"));
- let sw_script: _ = warp::path("sw.js").and(warp::fs::file("../client-web/public/assets/sw.js"));
+ let index: _ = warp::path!().and(s_file!("client-web/public/start.html"));
+ let room: _ = warp::path!("room").and(s_file!("client-web/public/app.html"));
+ let assets: _ = warp::path("assets").and(s_asset_dir!());
+ let sw_script: _ = warp::path("sw.js").and(s_file!("client-web/public/assets/sw.js"));
let favicon: _ = warp::path!("favicon.ico").map(|| "");
let old_format_redirect: _ = warp::path!("room" / String).map(|rsecret| {
reply::with_header(