aboutsummaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/src')
-rw-r--r--server/src/assets.rs69
-rw-r--r--server/src/main.rs48
2 files changed, 22 insertions, 95 deletions
diff --git a/server/src/assets.rs b/server/src/assets.rs
index 4ddb3a5..cf6ccb1 100644
--- a/server/src/assets.rs
+++ b/server/src/assets.rs
@@ -3,8 +3,6 @@
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2023 metamuffin <metamuffin.org>
*/
-use log::error;
-use std::sync::LazyLock;
#[cfg(debug_assertions)]
#[macro_export]
@@ -57,70 +55,3 @@ macro_rules! s_asset_dir {
})
}};
}
-
-#[derive(Debug)]
-struct GrassFs;
-#[cfg(debug_assertions)]
-impl GrassFs {
- pub fn map(p: &std::path::Path) -> std::path::PathBuf {
- std::path::PathBuf::from("../client-web/style").join(p.file_name().unwrap())
- }
-}
-#[cfg(debug_assertions)]
-impl grass::Fs for GrassFs {
- fn is_dir(&self, path: &std::path::Path) -> bool {
- Self::map(path).is_dir()
- }
- fn is_file(&self, path: &std::path::Path) -> bool {
- Self::map(path).is_file()
- }
- fn read(&self, path: &std::path::Path) -> std::io::Result<Vec<u8>> {
- std::fs::read(Self::map(path))
- }
-}
-
-#[cfg(not(debug_assertions))]
-const STYLE_DIR: include_dir::Dir =
- include_dir::include_dir!("$CARGO_MANIFEST_DIR/../client-web/style");
-#[cfg(not(debug_assertions))]
-impl grass::Fs for GrassFs {
- fn is_dir(&self, _path: &std::path::Path) -> bool {
- false
- }
- fn is_file(&self, path: &std::path::Path) -> bool {
- STYLE_DIR.get_file(path.file_name().unwrap()).is_some()
- }
- fn read(&self, path: &std::path::Path) -> std::io::Result<Vec<u8>> {
- Ok(STYLE_DIR
- .get_file(path.file_name().unwrap())
- .ok_or(std::io::Error::new(
- std::io::ErrorKind::NotFound,
- "not found",
- ))?
- .contents()
- .to_vec())
- }
-}
-
-static CSS_BUNDLE: LazyLock<String> = LazyLock::new(css_bundle);
-
-pub fn css() -> String {
- if cfg!(debug_assertions) {
- css_bundle()
- } else {
- CSS_BUNDLE.clone()
- }
-}
-fn css_bundle() -> String {
- grass::from_path(
- "/master.sass",
- &grass::Options::default()
- .input_syntax(grass::InputSyntax::Sass)
- .load_path("/")
- .fs(&GrassFs),
- )
- .unwrap_or_else(|err| {
- error!("sass compile failed: {err}");
- String::from("/* sass compile failed */")
- })
-}
diff --git a/server/src/main.rs b/server/src/main.rs
index e7a3674..92f9451 100644
--- a/server/src/main.rs
+++ b/server/src/main.rs
@@ -11,7 +11,6 @@ pub mod logic;
pub mod protocol;
use crate::protocol::ClientboundPacket;
-use assets::css;
use config::{AppearanceConfig, Config};
use futures_util::{SinkExt, StreamExt, TryFutureExt};
use listenfd::ListenFd;
@@ -62,8 +61,8 @@ async fn run() {
let index: _ = warp::path!().and(s_file!("client-web/public/start.html", "text/html"));
let favicon: _ =
- warp::path!("favicon.ico").and(s_file!("client-web/public/favicon.ico", "image/avif"));
- let room: _ = warp::path!("room").and(s_file!("client-web/public/app.html", "text/html"));
+ warp::path("favicon.ico").and(s_file!("client-web/public/favicon.ico", "image/avif"));
+ let room: _ = warp::path("room").and(s_file!("client-web/public/app.html", "text/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",
@@ -79,8 +78,6 @@ async fn run() {
let client_config_css: _ = warp::path!("overrides.css").map(move || {
warp::reply::with_header(client_config_css.clone(), "content-type", "text/css")
});
- let css: _ = warp::path!("style.css")
- .map(move || warp::reply::with_header(css(), "content-type", "text/css"));
let old_format_redirect: _ = warp::path!("room" / String).map(|rsecret| {
reply::with_header(
StatusCode::MOVED_PERMANENTLY,
@@ -92,27 +89,26 @@ async fn run() {
let version: _ = warp::path!("version").map(|| env!("CARGO_PKG_VERSION"));
let routes: _ = signaling
- .or(assets
- .or(room)
- .or(index)
- .or(client_config)
- .or(version)
- .or(css)
- .or(favicon)
- .or(sw_script)
- .or(old_format_redirect)
- .or(client_config_css)
- .map(|r| {
- warp::reply::with_header(
- r,
- "cache-control",
- if cfg!(debug_assertions) {
- "no-cache"
- } else {
- "max-age=1000000"
- },
- )
- }))
+ .or(room)
+ .or(index)
+ .or(client_config)
+ .or(version)
+ .or(assets)
+ .or(favicon)
+ .or(sw_script)
+ .or(old_format_redirect)
+ .or(client_config_css)
+ .map(|r| {
+ warp::reply::with_header(
+ r,
+ "cache-control",
+ if cfg!(debug_assertions) {
+ "no-cache"
+ } else {
+ "max-age=1000000"
+ },
+ )
+ })
.recover(handle_rejection)
.with(warp::log("keks-meet"))
.map(|r| warp::reply::with_header(r, "server", "keks-meet"));