pub struct ForgeBuilder { /* private fields */ }Expand description
Builder for configuring the FORGE runtime.
Implementations§
Source§impl ForgeBuilder
impl ForgeBuilder
pub fn new() -> Self
Sourcepub fn migrations_dir(self, path: impl Into<PathBuf>) -> Self
pub fn migrations_dir(self, path: impl Into<PathBuf>) -> Self
Set the directory to load migrations from.
Defaults to ./migrations. Migration files should be named like:
0001_create_users.sql0002_add_posts.sql
Sourcepub fn migration(self, name: impl Into<String>, sql: impl Into<String>) -> Self
pub fn migration(self, name: impl Into<String>, sql: impl Into<String>) -> Self
Add a migration programmatically.
Use this for migrations that need to be generated at runtime, or for testing. For most cases, use migration files instead.
Sourcepub fn frontend_handler(
self,
handler: fn(Request<Body>) -> Pin<Box<dyn Future<Output = Response> + Send>>,
) -> Self
pub fn frontend_handler( self, handler: fn(Request<Body>) -> Pin<Box<dyn Future<Output = Response> + Send>>, ) -> Self
Set a frontend handler for serving embedded SPA assets.
Use with the embedded-frontend feature to build a single binary
that includes both backend and frontend.
Sourcepub fn with_role_resolver(self, resolver: SharedRoleResolver) -> Self
pub fn with_role_resolver(self, resolver: SharedRoleResolver) -> Self
Plug in a custom role resolver for RBAC extension.
The default resolver returns the flat roles JWT claim as-is. Use
this to expand roles hierarchically, perform group-membership lookups,
or consult an external permission service.
The resolver is called for every request that carries a require_role
constraint. Keep it cheap — cache remote lookups internally.
Sourcepub fn custom_routes<F>(self, f: F) -> Self
pub fn custom_routes<F>(self, f: F) -> Self
Register custom axum routes built from Forge’s managed pool.
The factory runs once during run(), after the database pool is
connected. The returned router is merged into the gateway’s /_api
namespace, so every route receives the full middleware stack: auth
(JWT), CORS, tracing, concurrency limits, and timeouts.
Route paths are relative to /_api. Registering /export/csv
exposes GET /_api/export/csv. Avoid paths that collide with
built-ins under /_api: /health, /ready, /rpc, /rpc/*,
/events, /subscribe, /unsubscribe, /subscribe-job,
/subscribe-workflow, /signal/*, /mcp, and /oauth/*.
The factory receives the framework’s sqlx::PgPool. Cloning it is
cheap (PgPool is internally an Arc).
If your handlers don’t need the pool, ignore the argument:
builder.custom_routes(|_| Router::new().route("/healthz", get(|| async { "ok" })));With pool access:
use axum::{Router, routing::get};
builder.custom_routes(|pool| {
Router::new()
.route("/export/csv", get(export_handler))
.with_state(pool)
});Sourcepub fn auto_register(self) -> Self
pub fn auto_register(self) -> Self
Automatically register all functions discovered via #[forge::query],
#[forge::mutation], #[forge::job], #[forge::cron], #[forge::workflow],
#[forge::daemon], #[forge::webhook], and #[forge::mcp_tool] macros.
This replaces the need to manually call .register_query::<T>() etc.
for every function in your application.
pub fn config(self, config: ForgeConfig) -> Self
pub fn function_registry_mut(&mut self) -> &mut FunctionRegistry
pub fn job_registry_mut(&mut self) -> &mut JobRegistry
pub fn mcp_registry_mut(&mut self) -> &mut McpToolRegistry
pub fn register_mcp_tool<T: ForgeMcpTool>(self) -> Self
pub fn cron_registry_mut(&mut self) -> &mut CronRegistry
pub fn workflow_registry_mut(&mut self) -> &mut WorkflowRegistry
pub fn daemon_registry_mut(&mut self) -> &mut DaemonRegistry
pub fn webhook_registry_mut(&mut self) -> &mut WebhookRegistry
pub fn register_query<Q: ForgeQuery>(self) -> Self
pub fn register_mutation<M: ForgeMutation>(self) -> Self
pub fn register_job<J: ForgeJob>(self) -> Self
pub fn register_cron<C: ForgeCron>(self) -> Self
pub fn register_workflow<W: ForgeWorkflow>(self) -> Self
pub fn register_daemon<D: ForgeDaemon>(self) -> Self
pub fn register_webhook<W: ForgeWebhook>(self) -> Self
pub fn build(self) -> Result<Forge>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ForgeBuilder
impl !RefUnwindSafe for ForgeBuilder
impl Send for ForgeBuilder
impl Sync for ForgeBuilder
impl Unpin for ForgeBuilder
impl UnsafeUnpin for ForgeBuilder
impl !UnwindSafe for ForgeBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more