Serve static files

This commit is contained in:
2025-01-22 20:35:52 +01:00
parent b4a823a35f
commit f31e0ebbcc
6 changed files with 12320 additions and 5 deletions

View File

@ -7,6 +7,25 @@ use actix_session::Session;
use actix_web::{web, HttpResponse};
use light_openid::primitives::OpenIDConfig;
/// Static assets
#[derive(rust_embed::Embed)]
#[folder = "assets/"]
struct Assets;
/// Serve static file
pub async fn static_file(path: web::Path<String>) -> HttpResult {
match Assets::get(path.as_ref()) {
Some(content) => Ok(HttpResponse::Ok()
.content_type(
mime_guess::from_path(path.as_str())
.first_or_octet_stream()
.as_ref(),
)
.body(content.data.into_owned())),
None => Ok(HttpResponse::NotFound().body("404 Not Found")),
}
}
/// Main route
pub async fn home(session: Session) -> HttpResult {
// Get user information, requesting authentication if information is missing