Convert the TTX driver code to promises

This commit removes the final callbacks in this code by switching to a
promises-based interface, overall simplifying the code. Moreover, we
document why we write to files on disk and modernize the code using e.g.
template strings.
This commit is contained in:
Tim van der Meij 2024-04-05 13:03:22 +02:00
parent 64065141b6
commit ac03d7054d
No known key found for this signature in database
GPG key ID: 8C3FD2925A5F2762
2 changed files with 43 additions and 32 deletions

View file

@ -840,12 +840,14 @@ function unitTestPostHandler(req, res) {
req.on("data", function (data) {
body += data;
});
req.on("end", function () {
req.on("end", async function () {
if (pathname === "/ttx") {
translateFont(body, function (err, xml) {
res.writeHead(200, { "Content-Type": "text/xml" });
res.end(err ? "<error>" + err + "</error>" : xml);
});
res.writeHead(200, { "Content-Type": "text/xml" });
try {
res.end(await translateFont(body));
} catch (error) {
res.end(`<error>${error}</error>`);
}
return;
}