Skip to content

Commit

Permalink
Serve index.html on all paths
Browse files Browse the repository at this point in the history
This routes all non-API paths to the frontend even when the browser
is reloaded on a path other than `/`.
  • Loading branch information
praseodym committed Jul 24, 2024
1 parent 6eaa2b0 commit 49e1ba5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions backend/src/bin/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ async fn main() -> Result<(), Box<dyn Error>> {
let app = router(pool)?;

let app = if let Some(fd) = args.frontend_dist {
app.route_service("/", ServeFile::new(fd.join("index.html")))
.fallback_service(ServeDir::new(fd))
app.fallback_service(
ServeDir::new(fd.clone()).not_found_service(ServeFile::new(fd.join("index.html"))),
)
} else {
app
};
Expand Down

0 comments on commit 49e1ba5

Please sign in to comment.