fix(bridge): respect --fail-on-error in generation (#3134)

* fix(bridge): respect `--fail-on-error` in generation

* fix: use `res.ok()`
This commit is contained in:
Daniel Roe 2022-02-08 18:47:14 +00:00 committed by GitHub
parent a8c532be9a
commit c02e3683eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,7 @@
import { promises as fsp } from 'fs'
import fetch from 'node-fetch'
import { addPluginTemplate, useNuxt } from '@nuxt/kit'
import { stringifyQuery } from 'ufo'
import { joinURL, stringifyQuery } from 'ufo'
import { resolve } from 'pathe'
import { build, generate, prepare, getNitroContext, NitroContext, createDevServer, wpfs, resolveMiddleware, scanMiddleware, writeTypes } from '@nuxt/nitro'
import { AsyncLoadingPlugin } from './async-loading'
@ -216,9 +216,13 @@ function createNuxt2DevServer (nitroContext: NitroContext) {
if (!listener) {
throw new Error('There is no server listener to call `server.renderRoute()`')
}
const html = await fetch(listener.url + route, {
const res = await fetch(joinURL(listener.url, route), {
headers: { 'nuxt-render-context': stringifyQuery(renderContext) }
}).then(r => r.text())
})
const html = await res.text()
if (!res.ok) { return { html, error: res.statusText } }
return { html }
}