Make route-D the default flat preview engine
POST /preview served the v1 pipeline while route-D lived behind /api/route-d and the project engine switch. Try route_d::preview_json first and keep the v1 compiler as the fallback when route-D rejects the source; ?engine=v1 forces the old path and the project endpoints are unchanged. Both paths now answer with an X-Preview-Engine header (route-d or v1) so the choice is observable, and the server test helper compares header names case-insensitively because tiny-http lowercases them. A server test posts a document and checks route-d by default plus v1 when the query asks for it.
This commit is contained in:
1 parent
621a8abb92
commit
a56d441513
4 files changed
+59
-11
No files matched your search
+24
-1
@@ -231,8 +231,12 @@ fn handle_request(
|
||||
);
|
||||
}
|
||||
};
|
||||
let force_v1 = url.contains("engine=v1");
|
||||
if !force_v1 && let Ok(json) = route_d::preview_json(&source) {
|
||||
return respond_json_engine(request, 200, &json, "route-d");
|
||||
}
|
||||
match compiler.preview_json(&source, &input_path.display().to_string()) {
|
||||
Ok(json) => respond(request, 200, "application/json; charset=utf-8", &json),
|
||||
Ok(json) => respond_json_engine(request, 200, &json, "v1"),
|
||||
Err(error) => respond(
|
||||
request,
|
||||
422,
|
||||
@@ -386,6 +390,25 @@ fn respond(request: Request, status: u16, content_type: &str, body: &str) -> Res
|
||||
.map_err(|error| format!("could not send response: {error}"))
|
||||
}
|
||||
|
||||
fn respond_json_engine(
|
||||
request: Request,
|
||||
status: u16,
|
||||
body: &str,
|
||||
engine: &str,
|
||||
) -> Result<(), String> {
|
||||
let content_type = Header::from_bytes("Content-Type", "application/json; charset=utf-8")
|
||||
.map_err(|_| "invalid response header".to_string())?;
|
||||
let engine_header = Header::from_bytes("X-Preview-Engine", engine)
|
||||
.map_err(|_| "invalid response header".to_string())?;
|
||||
let response = Response::from_string(body)
|
||||
.with_status_code(StatusCode(status))
|
||||
.with_header(content_type)
|
||||
.with_header(engine_header);
|
||||
request
|
||||
.respond(response)
|
||||
.map_err(|error| format!("could not send response: {error}"))
|
||||
}
|
||||
|
||||
fn respond_with_cache(
|
||||
request: Request,
|
||||
content_type: &str,
|
||||
|
||||
Reference in new issue
Block a user