From 42405c252d9a50124566d0f15b5f7c40be463f3d Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 27 Jul 2021 14:55:01 +0100 Subject: [PATCH] fix(nitro): handle ssr redirects (#392) --- src/runtime/app/render.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/runtime/app/render.ts b/src/runtime/app/render.ts index 277d953635..2e9f00745e 100644 --- a/src/runtime/app/render.ts +++ b/src/runtime/app/render.ts @@ -1,3 +1,4 @@ +import type { ServerResponse } from 'http' import { createRenderer } from 'vue-bundle-renderer' import devalue from '@nuxt/devalue' import { runtimeConfig } from './config' @@ -47,7 +48,7 @@ function renderToString (ssrContext) { }) } -export async function renderMiddleware (req, res) { +export async function renderMiddleware (req, res: ServerResponse) { let url = req.url // payload.json request detection @@ -75,6 +76,10 @@ export async function renderMiddleware (req, res) { throw ssrContext.error } + if (ssrContext.redirected || res.writableEnded) { + return + } + if (ssrContext.nuxt.hooks) { await ssrContext.nuxt.hooks.callHook('app:rendered') }