Skip to content

Commit

Permalink
feat: allow await in IIFEs for code and pg
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhendumadhukar committed Aug 4, 2023
1 parent 61da2f5 commit ceefc9b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/handlebar/CodeHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export class CodeHelper {
* @returns {void}
*/
register = () => {
this.Handlebars.registerHelper("code", (context: any) => {
this.Handlebars.registerHelper("code", async (context: any) => {
/* eslint-disable no-unused-vars */
const request: express.Request = context.data.root.request;
const logger = context.data.root.logger;
/* eslint-disable no-unused-vars */
const code = eval(context.fn(this));
const code = await eval(context.fn(this));
code["CamouflageResponseType"] = "code";
return JSON.stringify(code);
});
Expand Down
2 changes: 1 addition & 1 deletion src/handlebar/PgHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class PgHelper {
const result = await pool.query(query)
log.debug(`[POSTGRES] Query response: ${JSON.stringify(result.rows)}`)
const fn = await context.fn(this)
const code = eval(fn);
const code = await eval(fn);
code["CamouflageResponseType"] = "code";
return JSON.stringify(code);
} catch (err) {
Expand Down
1 change: 1 addition & 0 deletions src/parser/HttpParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export class HttpParser {
responseBody = responseBody.replace(/}}}/, "}} }");
const template = Handlebars.compile(responseBody);
try {
responseBody = responseBody.split("<br/>").join("\n").trim()
const codeResponse = JSON.parse(
responseBody.replace(/&quot;/g, '"')
);
Expand Down

0 comments on commit ceefc9b

Please sign in to comment.