From 6a07c22e62f755a70d37fb09416380e5ba806dc5 Mon Sep 17 00:00:00 2001 From: User Last Date: Mon, 29 Jul 2019 15:55:44 +0300 Subject: [PATCH 1/2] Fix typo of `opts` as `e` --- lib/ejs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ejs.js b/lib/ejs.js index e8fa21ba..0f401f69 100755 --- a/lib/ejs.js +++ b/lib/ejs.js @@ -641,7 +641,7 @@ Template.prototype = { e.message += ' while compiling ejs\n\n'; e.message += 'If the above error is not helpful, you may want to try EJS-Lint:\n'; e.message += 'https://github.com/RyanZim/EJS-Lint'; - if (!e.async) { + if (!opts.async) { e.message += '\n'; e.message += 'Or, if you meant to create an async function, pass async: true as an option.'; } From a96e2f8aae5e4928f14d6f435e9199fafeea8a27 Mon Sep 17 00:00:00 2001 From: User Last Date: Mon, 29 Jul 2019 16:02:23 +0300 Subject: [PATCH 2/2] Add support for `async` option when using default Express.js backend --- lib/ejs.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/ejs.js b/lib/ejs.js index 0f401f69..a23fe69f 100755 --- a/lib/ejs.js +++ b/lib/ejs.js @@ -905,12 +905,25 @@ exports.escapeXML = utils.escapeXML; * Express.js support. * * This is an alias for {@link module:ejs.renderFile}, in order to support - * Express.js out-of-the-box. + * Express.js out-of-the-box. If rendered using async, a wrapper callback + * is passed to {@link module:ejs.renderFile} that waits until the returned + * promise is resolved and passes the result to Express.js * * @func */ -exports.__express = exports.renderFile; +exports.__express = function (file, opts, callback) { + if (opts.async) { + exports.renderFile(file, opts, function (err, promise) { + promise.then(function (data) { + callback(err, data); + }); + }); + } + else { + exports.renderFile(file, opts, callback); + } +}; // Add require support /* istanbul ignore else */