mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(nitro): promisify proxy handler (#398)
This commit is contained in:
parent
4a989e9b7a
commit
858e31c7fc
@ -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({}))
|
||||
|
Loading…
Reference in New Issue
Block a user