Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panel forward #193

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions crates/panel/src/handlers/panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,30 @@ use rust_embed::RustEmbed;
#[folder = "client/dist/"]
struct Asset;

/// Find the static assets of the administration panel
#[actix_web::get("/_panel{_:.*}")]
pub async fn handle_static_panel(path: web::Path<String>) -> impl Responder {
let path = if path.len() == 0 {
let path = if path.is_empty() {
"index.html"
} else {
path.as_str().strip_prefix('/').unwrap()
};

match Asset::get(path) {
Some(content) => HttpResponse::Ok()
.content_type(from_path(path).first_or_octet_stream().as_ref())
.body(content.data.into_owned()),
None => HttpResponse::NotFound().body("404 Not Found"),
}
let (content_type, content_data) = Asset::get(path)
.map(|content| {
(
from_path(path).first_or_octet_stream().to_string(),
content.data.into_owned(),
)
})
.unwrap_or_else(|| {
let default_content = Asset::get("index.html").unwrap();
(
"text/html; charset=utf-8".to_string(),
default_content.data.into_owned(),
)
});

HttpResponse::Ok()
.content_type(content_type)
.body(content_data)
}