From f6b583bb9db058ddcd11bfe58306ac3ddfc5e2a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Fri, 7 May 2021 09:32:06 -0400 Subject: [PATCH] feat: #9533, allow redirect in build hooks --- src/middleware/render.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/middleware/render.js b/src/middleware/render.js index 08f574dc5e..6e5ddb6074 100644 --- a/src/middleware/render.js +++ b/src/middleware/render.js @@ -34,9 +34,15 @@ module.exports = function (middleware) { options.bodyClass = buildBodyClass(req, res, options); const buildResult = await plugins.hooks.fire(`filter:${template}.build`, { req: req, res: res, templateData: options }); + if (res.headersSent) { + return; + } const templateToRender = buildResult.templateData.templateToRender || template; const renderResult = await plugins.hooks.fire('filter:middleware.render', { req: req, res: res, templateData: buildResult.templateData }); + if (res.headersSent) { + return; + } options = renderResult.templateData; options._header = { tags: await meta.tags.parse(req, renderResult, res.locals.metaTags, res.locals.linkTags),