diff --git a/packages/nitro/src/server/dev.ts b/packages/nitro/src/server/dev.ts index 0a43cde264..f7c54b1295 100644 --- a/packages/nitro/src/server/dev.ts +++ b/packages/nitro/src/server/dev.ts @@ -1,10 +1,11 @@ import { Worker } from 'worker_threads' +import { IncomingMessage, ServerResponse } from 'http' import { loading as loadingTemplate } from '@nuxt/design' import chokidar, { FSWatcher } from 'chokidar' import debounce from 'debounce' import { stat } from 'fs-extra' -import { createApp, Middleware, useBase } from 'h3' +import { promisifyHandle, createApp, Middleware, useBase } from 'h3' import { createProxy } from 'http-proxy' import { listen, Listener, ListenOptions } from 'listhen' import servePlaceholder from 'serve-placeholder' @@ -72,6 +73,9 @@ export function createDevServer (nitroContext: NitroContext) { // SSR Proxy const proxy = createProxy() + const proxyHandle = promisifyHandle((req: IncomingMessage, res: ServerResponse) => proxy.web(req, res, { target: workerAddress }, (_err: unknown) => { + // console.error('[proxy]', err) + })) app.use((req, res) => { if (workerAddress) { // Workaround to pass legacy req.spa to proxy @@ -79,9 +83,7 @@ export function createDevServer (nitroContext: NitroContext) { if (req.spa) { req.headers['x-nuxt-no-ssr'] = 'true' } - proxy.web(req, res, { target: workerAddress }, (_err: unknown) => { - // console.error('[proxy]', err) - }) + return proxyHandle(req, res) } else { res.setHeader('Content-Type', 'text/html; charset=UTF-8') res.end(loadingTemplate({}))