Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Frontend uses `@cryptgeon/shared` for crypto + payload codec (replacing the previous local `cryptgeon/shared`); heavy pack/unpack runs in a web worker.
- CLI rebuilt with `vite-plus` (bundles all deps) and imports from `@cryptgeon/shared`.

### Fixed

- SPA fallback now serves the app (200) for client-side routes such as `/about` and `/note/<id>`, while unmatched `/api/*` paths still return 404.

### Breaking changes

- Endpoints moved to `/api/v3/notes/` and `/api/v3/status`; health check to `/healthz`.
Expand Down
12 changes: 9 additions & 3 deletions packages/backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ mod note;
mod status;
mod store;

async fn api_not_found() -> axum::http::StatusCode {
axum::http::StatusCode::NOT_FOUND
}

#[tokio::main]
async fn main() {
dotenv().ok();
Expand All @@ -39,11 +43,13 @@ async fn main() {
.nest("/notes", notes_routes)
.merge(status_routes);

let api_routes = Router::new().nest("/v3", v3_routes);
let api_routes = Router::new()
.nest("/v3", v3_routes)
.fallback(api_not_found);

let index = format!("{}{}", config::FRONTEND_PATH.to_string(), "/index.html");
let serve_dir =
ServeDir::new(config::FRONTEND_PATH.to_string()).not_found_service(ServeFile::new(index));
ServeDir::new(config::FRONTEND_PATH.to_string()).fallback(ServeFile::new(index));
let app = Router::new()
.nest("/api", api_routes)
.merge(health_routes)
Expand All @@ -66,4 +72,4 @@ async fn main() {
axum::serve(listener, ServiceExt::<Request>::into_make_service(app))
.await
.unwrap();
}
}
15 changes: 15 additions & 0 deletions test/web/spa-fallback.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { expect, test } from "@playwright/test";

test.describe("@web", () => {
for (const path of ["/", "/about", "/note/does-not-exist"]) {
test(`serves ${path} with status 200`, async ({ request }) => {
const response = await request.get(path);
expect(response.status()).toBe(200);
});
}

test("api still reports a missing note as 404", async ({ request }) => {
const response = await request.get("/api/notes/does-not-exist");
expect(response.status()).toBe(404);
});
});
Loading