Skip to content

Commit

Permalink
Add some logging
Browse files Browse the repository at this point in the history
The timestamps accompanying these should be helpful for diagnosing #19.
  • Loading branch information
domenic committed Jun 24, 2021
1 parent a848dd1 commit b05796c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"extends": "@domenic",
"env": {
"node": true
},
"rules": {
"no-console": "off"
}
}
5 changes: 5 additions & 0 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,26 @@ router.post("/wattsi", bodyParser, async ctx => {

try {
try {
console.log(`Running wattsi ${args.join(" ")}`);
const result = await execFile("wattsi", args);

const outputFile = path.join(outDirectory, "output.txt");
await writeFile(outputFile, `${result.stdout}\n\n${result.stderr}`, { encoding: "utf-8" });
console.log(` wattsi succeeded`);
} catch (e) {
if (e.stdout) {
e.message = `${e.stdout}\n\n${e.stderr}`;
}
ctx.response.set("Wattsi-Exit-Code", e.code);
console.log(` wattsi failed: ${e.code}`);
ctx.throw(400, e.message);
}

ctx.response.set("Wattsi-Exit-Code", "0");
const zipFilePath = `${outDirectory}.zip`;
console.log(` zipping result`);
await execFile("7za", ["a", "-tzip", "-r", zipFilePath, `./${outDirectory}/*`]);
console.log(` zipping succeeded`);

ctx.response.type = "application/zip";
ctx.response.body = createReadStream(zipFilePath);
Expand Down

0 comments on commit b05796c

Please sign in to comment.