feat(minibf): add optional base_path configuration#872
feat(minibf): add optional base_path configuration#872adrian1-dot wants to merge 2 commits intotxpipe:mainfrom
Conversation
Allows nesting all routes under a custom prefix (e.g., /api/v0) for Blockfrost OpenAPI spec compliance. Backward compatible when unset.
📝 WalkthroughWalkthroughA new optional Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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`).
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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).
| if let Some(base_path) = &cfg.base_path { | ||
| if base_path.is_empty() || base_path == "/" { | ||
| panic!("base_path must not be empty or \"/\""); | ||
| } | ||
| Router::new().nest(base_path, app).layer(NormalizePathLayer::trim_trailing_slash()) |
There was a problem hiding this comment.
Validation doesn't catch a missing leading /, which will cause an opaque panic from Axum.
Axum's Router::nest() requires the path to start with "/" and will panic with its own less-descriptive message if it doesn't. Consider broadening the validation to also reject paths without a leading slash (and optionally paths containing wildcards *), so users get a clear configuration error.
Suggested fix
if let Some(base_path) = &cfg.base_path {
- if base_path.is_empty() || base_path == "/" {
- panic!("base_path must not be empty or \"/\"");
+ if base_path.is_empty() || base_path == "/" || !base_path.starts_with('/') || base_path.contains('*') {
+ panic!(
+ "base_path must start with '/', must not be just '/', and must not contain wildcards; got: \"{base_path}\""
+ );
}🤖 Prompt for AI Agents
In `@crates/minibf/src/lib.rs` around lines 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).
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
Documentation