Skip to content

Commit

Permalink
fix directory routing
Browse files Browse the repository at this point in the history
Signed-off-by: Bugen Zhao <[email protected]>
  • Loading branch information
BugenZhao committed Mar 14, 2024
1 parent f8f7f70 commit 64f6b0e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"express": "^4.18.1",
"prettier": "^2.7.1",
"prettier-plugin-organize-imports": "^3.1.1",
"typescript": "^5.4.2"
"typescript": "5.4.2"
},
"overrides": {
"react-json-view": {
Expand Down
18 changes: 11 additions & 7 deletions src/meta/dashboard/src/embed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,25 @@
// limitations under the License.

use axum::http::{header, StatusCode, Uri};
use axum::response::{Html, IntoResponse as _, Response};
use axum::response::{IntoResponse as _, Response};
use axum::Router;
use rust_embed::RustEmbed;

#[derive(RustEmbed)]
#[folder = "$OUT_DIR/assets"]
struct Assets;

// TODO: switch to `axum-embed` for better robustness after bumping to axum 0.7.
async fn static_handler(uri: Uri) -> Response {
let path = uri.path().trim_start_matches('/');

if path.is_empty() {
let data = Assets::get("index.html").unwrap().data;
return Html(data).into_response();
}
let path = {
if uri.path().ends_with('/') {
// Append `index.html` to directory paths.
format!("{}index.html", uri.path())
} else {
uri.path().to_owned()
}
};
let path = path.trim_start_matches('/');

match Assets::get(path) {
Some(file) => {
Expand Down

0 comments on commit 64f6b0e

Please sign in to comment.