feat(minibf): add optional base_path configuration#872
feat(minibf): add optional base_path configuration#872adrian1-dot wants to merge 4 commits intotxpipe:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 📝 WalkthroughWalkthroughAdded an optional Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@crates/core/src/config.rs`:
- Around line 572-575: Update the doc comment for the `base_path:
Option<String>` field in crates/core/src/config.rs to reflect the actual
behavior in `build_router()` (lib.rs): when `base_path` is set, all
routes—including `/health` and `/metrics`—are nested under that base path;
remove or correct the line that says "/health and /metrics remain at root" so
the comment matches the implementation (or, if you prefer the other approach,
modify `build_router()` to exclude `/health` and `/metrics` from nesting under
`base_path`).
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@crates/minibf/src/lib.rs`:
- Around line 442-446: The config validation for cfg.base_path is too narrow and
must also reject values missing a leading '/' (and optionally containing
wildcards) to avoid Axum's opaque panic when calling
Router::new().nest(base_path, app); update the check around cfg.base_path in
lib.rs to: ensure base_path is not empty, starts with '/', is not just "/" (as
already done), and does not contain '*' (or other invalid characters you choose
to forbid); if validation fails, panic or return a clear error message
referencing cfg.base_path so callers see a helpful configuration error before
reaching Router::nest (which is where NormalizePathLayer::trim_trailing_slash()
is applied).
crates/minibf/src/lib.rs
Outdated
| panic!( | ||
| "base_path must start with '/', must not be just '/', and must not contain wildcards; got: \"{}\"", | ||
| base_path |
There was a problem hiding this comment.
we should avoid a panic and instead bubble up an error, ideally a "config" error variant.
There was a problem hiding this comment.
I've addressed the panic by adding a ConfigError(String) variant to ServeError in dolos-core and changing build_router to return Result<Router, ServeError>. Invalid base_path values now return Err(ServeError::ConfigError(...)) instead of panicking, propagating through Driver::run consistently with BindError and ShutdownError.
I've also rebased onto the current main to resolve the CI conflicts.
Allows nesting all routes under a custom prefix (e.g., /api/v0) for Blockfrost OpenAPI spec compliance. Backward compatible when unset.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
- Check for leading '/' to prevent Axum panic - Reject wildcard characters - Improve error message with actual value
4da0643 to
f1a5f18
Compare
Add optional base_path configuration for Blockfrost API spec compliance
Problem
The Blockfrost OpenAPI specification defines all API endpoints under the
/api/v0base path (seeserverssection in the official spec). However, Dolos minibf currently serves endpoints directly at the root level (e.g.,/network,/blocks/latest), which breaks compatibility with tools and libraries that expect canonical Blockfrost endpoint paths.This incompatibility causes integration issues with:
/api/v0base pathSolution
Add an optional
base_pathconfiguration field toMinibfConfigthat allows nesting all routes under a custom prefix.Configuration example:
When configured:
{base_path}/{endpoint}(e.g.,/api/v0/network)Changes
base_path: Option<String>field toMinibfConfigbuild_router()to conditionally nest all routes whenbase_pathis set (~7 lines)base_pathto default configuration initializationImplementation Details
The implementation uses Axum's
Router::nest()to wrap the entire route tree under the custom base path when configured:This approach minimizes code changes while providing complete Blockfrost spec compliance.
Backwards Compatibility
base_pathis not configured, all routes remain at root level exactly as before.Testing
cargo test --workspace --all-features)cargo clippy --workspace --all-features)/api/v0base path/api/v0/*with base_path configuredImpact
This change enables Dolos minibf to serve as a drop-in replacement for Blockfrost API in tools requiring canonical endpoint paths, significantly improving ecosystem compatibility while maintaining flexibility for users who prefer root-level routes.
Summary by CodeRabbit
New Features
Bug Fixes
Documentation