Skip to content

fix(webmvc): avoid index fallback exception for missing public routes#298

Open
zachyale wants to merge 1 commit intodevelopfrom
fix/backend-webmvc-missing-index-fallback
Open

fix(webmvc): avoid index fallback exception for missing public routes#298
zachyale wants to merge 1 commit intodevelopfrom
fix/backend-webmvc-missing-index-fallback

Conversation

@zachyale
Copy link
Copy Markdown
Member

@zachyale zachyale commented Mar 31, 2026

Description

Fixes backend only error handling for unresolved public routes that were falling into static index fallback behaviour, and producing FileNotFoundException/500 log paths when app://-/index.html is not present. This occurs because WebMvcConfig is expecting index.html to exist all of the time, when it only exists when the frontend is bundled with the backend. As a result, this could cause 500s on local backend only runs.

This change makes unresolved requests return normal API/web behavior (404/403 as appropriate) instead of attempting to resolve a missing SPA index resource.

Linked Issue: Fixes #297

Changes

  • Updated WebMvcConfig static resource fallback behaviour to avoid attempting to resolve a non-existent index.html
  • Ensures that unresolved backend/API requests fall through cleanly, rather than triggering classpath lookup exceptions
  • Preserves normal static resource serving when files are present.
  • Verified the system behaviiour both pre- and post- fix, on both a backend only run and and a full build

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced static resource handling with improved validation checks to ensure resources exist and are readable before being served. The application now properly manages edge cases where resources may be unavailable or unreadable, preventing potential serving errors and improving reliability for single-page applications.

Return normal 404 behaviour when static resources are missing in backend only runs, by preventing a fallback to a missing index handler for unresolved routes
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 31, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ff70d5a8-936d-45a8-9db4-698387aab3e8

📥 Commits

Reviewing files that changed from the base of the PR and between f1cbcf3 and cb0ecbb.

📒 Files selected for processing (1)
  • booklore-api/src/main/java/org/booklore/config/WebMvcConfig.java
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Test Suite / Backend Tests
  • GitHub Check: Test Suite / Frontend Tests
  • GitHub Check: Analyze (java-kotlin)
  • GitHub Check: Analyze (javascript-typescript)
🧰 Additional context used
📓 Path-based instructions (1)
booklore-api/src/**/*.java

📄 CodeRabbit inference engine (AGENTS.md)

booklore-api/src/**/*.java: Use 4-space indentation in Java files and match surrounding Java style
Prefer constructor injection via Lombok patterns already used in the codebase. Do not introduce @Autowired field injection
Use MapStruct for entity/DTO mapping

Files:

  • booklore-api/src/main/java/org/booklore/config/WebMvcConfig.java
🔇 Additional comments (1)
booklore-api/src/main/java/org/booklore/config/WebMvcConfig.java (1)

45-50: LGTM: static fallback now safely avoids missing-index exceptions.

The new existence/readability checks for both the requested resource and index.html, with null fallback, correctly prevents the backend-only 500 path while preserving SPA fallback when assets are present.


📝 Walkthrough

Walkthrough

The change updates the SPA/static resource fallback logic in WebMvcConfig to verify that the index.html resource exists and is readable before returning it. If unavailable, the method returns null instead of throwing an exception when serving non-existent routes.

Changes

Cohort / File(s) Summary
Static Resource Fallback Logic
WebMvcConfig.java
Added existence and readability checks to the index.html fallback resource handler. Returns null instead of constructing an unavailable ClassPathResource, preventing FileNotFoundException when frontend assets are not bundled.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested labels

backend, enhancement

Poem

🐰 A rabbit checks twice before leaping,
"Does this resource exist?" it queries with care,
No more exceptions for paths that aren't there—
Just graceful nulls where the files aren't keeping. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title follows conventional commit format with 'fix' type and descriptive scope/subject about preventing index fallback exceptions.
Description check ✅ Passed The PR description includes all required sections (Description, Changes) with clear explanation of the issue, solution, and links to issue #297.
Linked Issues check ✅ Passed Changes fully address issue #297 by verifying resource existence/readability before returning index.html, preventing FileNotFoundException and allowing normal 404 handling.
Out of Scope Changes check ✅ Passed All changes are scoped to WebMvcConfig resource handler logic and directly address the issue of missing index.html fallback behavior.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/backend-webmvc-missing-index-fallback
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/backend-webmvc-missing-index-fallback

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing permitAll routes can trigger static index fallback exceptions instead of 404s

1 participant