Skip to content

feat: Surface RelicRouter.fallback in WebServer" - #4076

Merged
nielsenko merged 6 commits into
serverpod:mainfrom
nielsenko:webserver-fallback
Oct 23, 2025
Merged

nielsenko merged 6 commits into
serverpod:mainfrom
nielsenko:webserver-fallback

Conversation

@nielsenko

@nielsenko nielsenko commented Oct 23, 2025 •

Copy link
Copy Markdown
Collaborator

Description

Adds WebServer.fallbackRoute property to allow custom handling of unmatched requests. When set, the fallback route is invoked instead of the default "404 Not Found" response.

Additional changes to support this feature:

  • Updates WebServer to use RelicApp instead of Router, migrating middleware and route handling to the new API
  • Refactors Route to extend HandlerObject and adds a path property that determines the suffix path where the route responds
  • Makes the path parameter in WebServer.addRoute optional, defaulting to /
  • Updates StaticRoute to use StaticHandler constructors instead of createStaticHandler and createFileHandler
  • Bumps Relic dependency to git ref nielsenko/prep-0.8.0 to support new APIs

Fixes: #4042

Pre-launch Checklist

  • I read the Contribute page and followed the process outlined there for submitting PRs.
  • This update contains only one single feature or bug fix and nothing else. (If you are submitting multiple fixes, please make multiple PRs.)
  • I read and followed the Dart Style Guide and formatted the code with dart format.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.

Breaking changes

  • Route now extends HandlerObject and includes a path property. Technically this is a breaking change, since you can implement Route instead of extending it.

Summary by CodeRabbit

  • Refactor

    • Updated internal routing and middleware system to improve request handling architecture.
    • Enhanced route configuration with improved path handling capabilities.
    • Updated server initialization for optimized adapter lifecycle management.
  • Chores

    • Updated relic dependency to use git-based source with latest preparation build.
    • Updated test utilities to align with dependency changes.

@coderabbitai

coderabbitai Bot commented Oct 23, 2025 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

This PR migrates the Serverpod web server from a Router-based routing architecture to RelicApp, updates the relic dependency to a git-based pre-release version, adopts lazy factory initialization for IOAdapter, and refactors the Route interface and middleware hierarchy to align with the new routing framework.

Changes

Cohort / File(s) Summary
Relic dependency updates
packages/serverpod/pubspec.yaml, packages/serverpod_client/pubspec.yaml, templates/pubspecs/packages/serverpod/pubspec.yaml, templates/pubspecs/packages/serverpod_client/pubspec.yaml, templates/pubspecs/tests/serverpod_test_server/pubspec.yaml, tests/serverpod_test_server/pubspec.yaml
Replaced version constraint ^0.7.0 with git-based dependency pointing to https://github.com/nielsenko/relic.git ref prep-0.8.0 across serverpod and serverpod_client packages.
IOAdapter lazy initialization
packages/serverpod/lib/src/server/server.dart, packages/serverpod_client/test/test_utils/test_http_server.dart, packages/serverpod_client/test/test_utils/test_web_socket_server.dart
Changed from passing direct IOAdapter instances to RelicServer constructor to passing factory functions () => IOAdapter(...) for deferred adapter creation.
Static route handler migration
packages/serverpod/lib/src/web_server/routes/static_route.dart
Replaced createStaticHandler and createFileHandler calls with StaticHandler.directory(...) and StaticHandler.file(...) respectively, using .asHandler conversion.
Web server routing and middleware refactor
packages/serverpod/lib/src/web_server/web_server.dart
Replaced Router-based routing with RelicApp; refactored Route to extend HandlerObject with public path field and injectIn(RelicRouter) method; refactored _SessionMiddleware and _ReportExceptionMiddleware to extend MiddlewareObject; updated addRoute, addMiddleware, start(), and added public fallbackRoute setter.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant RelicApp
    participant Route as Route<br/>(extends HandlerObject)
    participant Middleware as Middleware<br/>(extends MiddlewareObject)
    participant Handler

    Client->>RelicApp: HTTP Request
    RelicApp->>Middleware: apply middleware chain
    Middleware->>RelicApp: next (handler)
    RelicApp->>Route: route.injectIn(router)
    Route->>Route: anyOf(methods, path, asHandler)
    Route->>Handler: asHandler conversion
    Handler->>Route: call(context)
    Route->>Client: response

    Note over RelicApp,Handler: New flow: RelicApp groups routes<br/>and injects via injectIn(router)
Loading
sequenceDiagram
    participant Code
    participant RelicServer
    participant IOAdapter
    participant HttpServer

    Code->>RelicServer: RelicServer(() => IOAdapter(...))
    Note over Code,RelicServer: Factory function passed (lazy init)
    RelicServer->>RelicServer: start()
    RelicServer->>IOAdapter: invoke factory: () => IOAdapter(...)
    IOAdapter->>HttpServer: bind to port
    HttpServer->>RelicServer: server ready
    Code->>RelicServer: server.port
    RelicServer->>Code: bound port (from HttpServer)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

This PR contains substantial architectural changes to the routing system (Router → RelicApp), public API modifications to the Route interface, middleware hierarchy refactoring, and consistent cross-package dependency updates. While the changes follow a cohesive pattern, they span multiple interconnected files and require verification of the migration logic, middleware injection correctness, and adapter lazy initialization semantics.

Possibly related PRs

Pre-merge checks and finishing touches

✅ Passed checks (4 passed)
Check name Status Explanation
Title Check ✅ Passed The title "feat: Surface RelicRouter.fallback in WebServer" directly refers to the primary feature being implemented in this PR. The PR description identifies adding the WebServer.fallbackRoute property as the main objective, with the WebServer/RelicApp migration and Route refactoring explicitly described as "Additional changes to support this feature." The title accurately captures the key feature from the developer's perspective and is clear and specific enough for a teammate to understand the primary change when scanning history.
Linked Issues Check ✅ Passed The PR directly implements the objective stated in issue #4042 by adding WebServer.fallbackRoute property to allow custom handling of unmatched requests. The code changes include the fallbackRoute setter, RelicApp-based routing infrastructure, Route refactoring with path properties, and supporting updates to StaticRoute and RelicServer initialization patterns. All changes are necessary to implement fallback route functionality with the new Relic 0.8.0 APIs.
Out of Scope Changes Check ✅ Passed All code changes in this PR appear directly aligned with implementing the fallback route feature for issue #4042. The WebServer migration to RelicApp, Route refactoring to include path properties, StaticRoute updates to use new StaticHandler APIs, RelicServer IOAdapter lazy initialization, and Relic dependency updates to prep-0.8.0 are all necessary supporting infrastructure changes explicitly described in the PR as required to enable the fallback route functionality. No extraneous or unrelated changes are present.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@nielsenko

nielsenko commented Oct 23, 2025 •

Copy link
Copy Markdown
Collaborator Author

You can disregard the analysis errors. These are due to the git ref introduced in 4f25093.

The particular commit will be replaced before merge, once relic 0.8.0 is released.

@nielsenko

Copy link
Copy Markdown
Collaborator Author

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented Oct 23, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nielsenko nielsenko self-assigned this Oct 23, 2025
@nielsenko
nielsenko marked this pull request as ready for review October 23, 2025 06:25
@nielsenko
nielsenko requested review from a team, SandPod and Copilot October 23, 2025 06:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for custom fallback routes in WebServer by exposing the RelicRouter.fallback functionality. When set, the fallback route is invoked for unmatched requests instead of returning the default "404 Not Found" response.

Key changes:

  • Migrates WebServer from Router to RelicApp to support the fallback route API
  • Updates Route to extend HandlerObject with a path property for suffix path handling
  • Updates Relic dependency to git reference nielsenko/[email protected]

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/serverpod/lib/src/web_server/web_server.dart Migrates from Router to RelicApp, adds fallbackRoute setter, updates middleware to extend MiddlewareObject, adds path property to Route class
packages/serverpod/lib/src/web_server/routes/static_route.dart Updates StaticRoute to use StaticHandler constructors instead of create functions
packages/serverpod/lib/src/server/server.dart Updates RelicServer initialization to use adapter factory function
packages/serverpod_client/test/test_utils/test_web_socket_server.dart Updates test server to use IOAdapter.bind factory and server.port property
packages/serverpod_client/test/test_utils/test_http_server.dart Updates test server to use IOAdapter.bind factory and server.port property
packages/serverpod/pubspec.yaml Updates relic dependency to git source
packages/serverpod_client/pubspec.yaml Updates relic dependency to git source
templates/pubspecs/packages/serverpod/pubspec.yaml Updates relic dependency template to git source
templates/pubspecs/packages/serverpod_client/pubspec.yaml Updates relic dependency template to git source
templates/pubspecs/tests/serverpod_test_server/pubspec.yaml Updates relic dependency template to git source
tests/serverpod_test_server/pubspec.yaml Updates relic dependency to git source

@SandPod SandPod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes looks good! Just had one suggestion.

But let's not merge it until we have a relic to keep main shippable.

@SandPod SandPod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 👍

@nielsenko

Copy link
Copy Markdown
Collaborator Author

Rebased after release of relic 0.8.0.

@nielsenko
nielsenko merged commit d30d5c9 into serverpod:main Oct 23, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for fallback route to WebServer

3 participants