Repository navigation
refactor: Use RelicApp in Server - #4134
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 📝 WalkthroughWalkthroughThe PR introduces two major refactorings: (1) simplifies error handling by replacing Result-object classes with a direct AuthenticationFailureReason enum in endpoint dispatch, and (2) refactors server request routing to use Router from the relic package via middleware injection, replacing manual path/HTTP verb dispatch. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant RelicRouter
participant Server
participant Middleware
participant Endpoints
rect rgb(200, 230, 201)
Note over Client,RelicRouter: Request enters via Router
end
Client->>RelicRouter: HTTP Request
RelicRouter->>Middleware: _verboseLogging
Middleware->>Middleware: _headers
Middleware->>Middleware: _reportException
alt Health Check
Middleware->>Server: GET /
Server-->>Client: Health metrics (OK/SADNESS)
else Endpoint Request
Middleware->>Endpoints: Route to handler
rect rgb(255, 242, 204)
Note over Endpoints: canUserAccessEndpoint check
end
Endpoints->>Endpoints: Authenticate & Authorize
alt Success
Endpoints->>Endpoints: Invoke endpoint method
Endpoints-->>Client: HTTP Response
else AuthenticationFailureReason
Endpoints->>Endpoints: Construct NotAuthorizedException
Endpoints-->>Client: 401/403 Response
end
else WebSocket Upgrade
Middleware->>Server: _dispatchWebSocket
Server-->>Client: WebSocket Connection
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes
Possibly related PRs
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
3528654 to
d736baf
Compare
d6fb252 to
32d5fb6
Compare
- Extract _health handler - Extract web service dispatch handler - Let middleware handle errors - Use middleware for default headers - Split endpoint and cloud storage handling at the router level. - Use middleware for logging
…irectly - Changed _handleUriCall to return Response instead of EndpointResult - Exceptions now propagate to _reportException middleware which constructs Response objects directly - Removed _toResponse method (no longer needed) - Removed EndpointResult and all its subclasses (not part of public API) - Updated NotAuthorizedException to store AuthenticationFailureReason directly instead of ResultAuthenticationFailed - Updated EndpointDispatch.canUserAccessEndpoint to return AuthenticationFailureReason? instead of ResultAuthenticationFailed? - Updated authentication tests to check AuthenticationFailureReason directly - Make EndpointDispatchException sealed.
|
@CodeRabbit review |
✅ Actions performedReview triggered.
|
32d5fb6 to
3a199f8
Compare
|
@CodeRabbit review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
packages/serverpod/lib/src/server/endpoint_dispatch.dart(5 hunks)packages/serverpod/lib/src/server/server.dart(11 hunks)packages/serverpod/lib/src/server/websocket_request_handlers/method_websocket_request_handler.dart(1 hunks)packages/serverpod/test/endpoint/authentication_test.dart(7 hunks)packages/serverpod_test/lib/src/function_call_wrappers.dart(1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.dart
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.dart: Format all Dart code usingdart format .before committing
Code must pass Dart analyzer in strict mode (util/run_tests_analyze or melos lint_strict)
Use descriptive variable and function names
Files:
packages/serverpod/lib/src/server/websocket_request_handlers/method_websocket_request_handler.dartpackages/serverpod/lib/src/server/server.dartpackages/serverpod/test/endpoint/authentication_test.dartpackages/serverpod_test/lib/src/function_call_wrappers.dartpackages/serverpod/lib/src/server/endpoint_dispatch.dart
**/lib/**/*.dart
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Remove unnecessary comments from production code
Files:
packages/serverpod/lib/src/server/websocket_request_handlers/method_websocket_request_handler.dartpackages/serverpod/lib/src/server/server.dartpackages/serverpod_test/lib/src/function_call_wrappers.dartpackages/serverpod/lib/src/server/endpoint_dispatch.dart
**/*_test.dart
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*_test.dart: Write test descriptions using the Given/When/Then pattern
Organize tests with passing/success cases first, group related cases using group(), then follow with error cases
Files:
packages/serverpod/test/endpoint/authentication_test.dart
🧠 Learnings (9)
📚 Learning: 2025-09-17T16:09:20.868Z
Learnt from: nielsenko
Repo: serverpod/serverpod PR: 3980
File: packages/serverpod/lib/src/web_server/web_server.dart:102-115
Timestamp: 2025-09-17T16:09:20.868Z
Learning: In Serverpod's web server authentication handling (packages/serverpod/lib/src/web_server/web_server.dart), query parameter authentication fallback (`authenticationKey ??= queryParameters['auth']`) is intentionally maintained for legacy compatibility reasons, even though it has security implications regarding credential leakage.
Applied to files:
packages/serverpod/lib/src/server/websocket_request_handlers/method_websocket_request_handler.dartpackages/serverpod/lib/src/server/server.dartpackages/serverpod/test/endpoint/authentication_test.dartpackages/serverpod_test/lib/src/function_call_wrappers.dartpackages/serverpod/lib/src/server/endpoint_dispatch.dart
📚 Learning: 2025-11-04T12:09:52.649Z
Learnt from: marcelomendoncasoares
Repo: serverpod/serverpod PR: 4150
File: examples/auth/auth_flutter/lib/widgets/profile_info.dart:23-30
Timestamp: 2025-11-04T12:09:52.649Z
Learning: In Serverpod example and testing projects (e.g., examples/auth/auth_flutter), prefer letting errors bubble up naturally rather than handling them gracefully with catchError or try-catch blocks. This helps developers see what went wrong during development and testing.
Applied to files:
packages/serverpod/lib/src/server/websocket_request_handlers/method_websocket_request_handler.dartpackages/serverpod/test/endpoint/authentication_test.dartpackages/serverpod_test/lib/src/function_call_wrappers.dart
📚 Learning: 2025-08-26T13:22:33.125Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3829
File: modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_accounts.dart:0-0
Timestamp: 2025-08-26T13:22:33.125Z
Learning: The passkeys_server Dart library evolved from version 0.3.0 to 0.4.0, adding required parameters to verifyRegistration and verifyLogin methods for complete WebAuthn security validation including challenge, clientDataJSON, and attestationObject verification.
Applied to files:
packages/serverpod/lib/src/server/websocket_request_handlers/method_websocket_request_handler.dartpackages/serverpod/test/endpoint/authentication_test.dart
📚 Learning: 2025-07-02T16:07:50.947Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3747
File: modules/new_serverpod_auth/serverpod_auth_migration/serverpod_auth_migration_server/lib/src/business/migrating_email_endpoint_base.dart:4-4
Timestamp: 2025-07-02T16:07:50.947Z
Learning: In Serverpod, tp prefers importing the full package (e.g., 'package:serverpod_auth_migration_server/serverpod_auth_migration_server.dart') as a baseline rather than using smaller local imports, even within the same package where it might be considered a "self-import".
Applied to files:
packages/serverpod/lib/src/server/server.dartpackages/serverpod_test/lib/src/function_call_wrappers.dart
📚 Learning: 2025-11-03T15:40:41.827Z
Learnt from: SandPod
Repo: serverpod/serverpod PR: 4144
File: modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/endpoints/passkey_idp_base_endpoint.dart:0-0
Timestamp: 2025-11-03T15:40:41.827Z
Learning: In Serverpod authentication IDP endpoint files (modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server), endpoint base classes should import `serverpod_auth_idp_server/core.dart` to access the Session type, rather than importing `package:serverpod_auth_core_server/session.dart` directly. This pattern is consistently used in Apple, Email, and Google endpoint files.
Applied to files:
packages/serverpod/lib/src/server/server.dartpackages/serverpod/test/endpoint/authentication_test.dartpackages/serverpod_test/lib/src/function_call_wrappers.dartpackages/serverpod/lib/src/server/endpoint_dispatch.dart
📚 Learning: 2025-08-25T19:46:58.073Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3917
File: modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/analysis_options.yaml:3-6
Timestamp: 2025-08-25T19:46:58.073Z
Learning: In Serverpod, test tool paths like `test/integration/test_tools/serverpod_test_tools.dart` are configured per project in the "generator.yaml" file and managed by a generator system, so they don't need to be updated manually across all files at once.
Applied to files:
packages/serverpod/lib/src/server/server.dart
📚 Learning: 2025-07-03T09:16:08.642Z
Learnt from: nielsenko
Repo: serverpod/serverpod PR: 3625
File: packages/serverpod/lib/src/cloud_storage/public_endpoint.dart:82-93
Timestamp: 2025-07-03T09:16:08.642Z
Learning: In Serverpod's CloudStoragePublicEndpoint, the _readBinaryBody method must buffer the entire request body in memory because the storage.storeFile interface requires a ByteData object. Implementing true streaming uploads would require reworking Serverpod's serialization handling of binary arguments. The current implementation uses BytesBuilder for efficient byte accumulation instead of list concatenation.
Applied to files:
packages/serverpod/lib/src/server/server.dart
📚 Learning: 2025-06-18T14:49:11.263Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3672
File: tests/serverpod_test_server/test_integration/test_tools/test_session_builder_test.dart:10-30
Timestamp: 2025-06-18T14:49:11.263Z
Learning: In Serverpod test files, tp prefers using nullable late variables for AuthenticationInfo in tests (e.g., `late AuthenticationInfo? authenticationInfo;`) rather than non-nullable ones to avoid using `!` operators and to get clearer error messages when authentication setup fails. This provides better diagnostics when `session.authenticated` returns null.
Applied to files:
packages/serverpod/test/endpoint/authentication_test.dartpackages/serverpod_test/lib/src/function_call_wrappers.dartpackages/serverpod/lib/src/server/endpoint_dispatch.dart
📚 Learning: 2025-07-02T16:09:27.702Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3747
File: tests/serverpod_new_auth_test/serverpod_new_auth_test_server/pubspec.yaml:37-38
Timestamp: 2025-07-02T16:09:27.702Z
Learning: In Serverpod migration testing, it's appropriate for test servers like serverpod_new_auth_test_server to include dependencies on both legacy packages (e.g., serverpod_auth_server) and new modular packages to enable comprehensive testing of migration paths from old to new authentication systems.
Applied to files:
packages/serverpod/test/endpoint/authentication_test.dart
ba1561a to
eba4895
Compare
SandPod
left a comment
There was a problem hiding this comment.
Changes looks good, have a couple of comments and minor suggestions.
Summary
Use Relic's router for endpoint dispatch in api server.
Closes: #4101
Changes
RouterInjectableand useRelicAppfor request routingEndpointResultclasses._handleUriCallto returnResponsedirectly instead ofEndpointResult_reportExceptionmiddlewareEndpointDispatchExceptionsealed to enable exhaustive pattern matchingNotAuthorizedExceptionto storeAuthenticationFailureReasondirectlycanUserAccessEndpointto returnAuthenticationFailureReason?instead of result wrappersessionLogIdfrom error responses to avoid exposing internal database IDs_toResponseand_logMalformedCalls(no longer needed)Pre-launch Checklist
///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.Breaking changes
None. This is an internal refactoring that doesn't affect the public API.
Summary by CodeRabbit
Release Notes
New Features
Refactor