sync_export
.gest/ after each web write.Every CLI command imports .gest/ into the database before it runs, and exports the database back when it exits.
gest serve runs as one long command, so without this layer its writes reach only the database, and the next CLI
command’s import puts the older .gest/ files back over them.
fn export_after_write
pub async fn export_after_write(
State(state): State<AppState>,
request: Request,
next: Next,
) -> ResponseMiddleware that keeps .gest/ and the database in step around each web write.
A write is any request that is not GET or HEAD, except the Markdown preview, which only renders. For a write it
holds the store’s web write lock, imports .gest/ first, so files a git pull added while serve runs are in the
database, runs the handler, and then exports. It exports whatever the handler answered, because a handler can fail
after saving part of a write. When the import or export fails, it answers 500 instead of the handler’s response, so
the browser does not show a save that the next CLI command would undo. It does nothing more when sync is off.
| Parameter | Type | Description |
|---|---|---|
State(state) |
State<AppState> | the shared state, whose store holds the sync settings |
request |
Request | the incoming request |
next |
Next | the rest of the middleware stack and the handler |
| returns | Response | The handler’s response, or a 500 response when syncing .gest/ failed. |
fn sync_failed
fn sync_failed(verb: &str, error: &dyn std::fmt::Display) -> ResponseA 500 response saying that syncing .gest/ failed.
| Parameter | Type | Description |
|---|---|---|
verb |
&str | |
error |
&dyn std::fmt::Display | |
| returns | Response |