From 8c1f1f4053ad4237ea28ed83469641731047aaf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Rame=CC=81?= Date: Fri, 10 Jun 2022 18:00:51 +0200 Subject: [PATCH] Fix HTTP server errors when trying to do a HTTP redirect from components --- lib/app.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/app.js b/lib/app.js index d19e816..a89d42a 100644 --- a/lib/app.js +++ b/lib/app.js @@ -123,6 +123,11 @@ module.exports = (app, options) => { renderer.renderToString(context, (err, renderedHtml) => { let html = renderedHtml + if (context.httpCode !== res.statusCode) { + // If someone asked for a redirection through `this.$ssrContext.req.res.redirect(302, redirectUri)` for example, take it in account + context.httpCode = res.statusCode + } + if (err || context.httpCode === 500) { console.error(`error during render url : ${req.url}`) @@ -157,7 +162,10 @@ module.exports = (app, options) => { config.onRender(res, context) } - res.send(html) + // In case it's a redirection the body should be sent + if (res.statusCode !== 301 && res.statusCode !== 302) { + res.send(html) + } }) }