Skip to content

Commit 73b7a3c

Browse files
authored
fix(studio): appropriately route requests to correct page (#279)
1 parent 6f0580e commit 73b7a3c

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/studio/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "surfpool-studio-ui"
33
description = "Crate for starting the surfpool studio UI"
4-
version = "0.1.0"
4+
version = "0.1.1"
55
edition = { workspace = true }
66
license = { workspace = true }
77
repository = { workspace = true }

crates/studio/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,19 @@ pub static ASSETS: Dir<'_> = include_dir!("$OUT_DIR/surfpool-studio-ui");
88
#[get("/{_:.*}")]
99
async fn serve_studio_static_files(req: HttpRequest) -> impl Responder {
1010
let path = req.path().trim_start_matches('/');
11+
1112
let file = if path.is_empty() {
13+
// root request → serve root index.html
1214
ASSETS.get_file("index.html")
1315
} else {
16+
// Try exact file first
1417
ASSETS
1518
.get_file(path)
19+
// Then try {path}.html (file request)
20+
.or_else(|| ASSETS.get_file(format!("{}.html", path)))
21+
// Then try {path}/index.html (directory request)
22+
.or_else(|| ASSETS.get_file(format!("{}/index.html", path)))
23+
// Then fallback to root index.html for SPA routing
1624
.or_else(|| ASSETS.get_file("index.html"))
1725
};
1826

0 commit comments

Comments
 (0)