fix(nitro): handle ssr redirects (#392)

This commit is contained in:
Daniel Roe 2021-07-27 14:55:01 +01:00 committed by GitHub
parent ef0190be02
commit bbfa41f811
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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')
}