Skip to content

Commit

Permalink
fix: handle http proxy error
Browse files Browse the repository at this point in the history
fix #1485
  • Loading branch information
yyx990803 committed Jan 11, 2021
1 parent 803f6da commit 4ca20f2
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/vite/src/node/server/middlewares/proxy.ts
Expand Up @@ -5,6 +5,7 @@ import { HMR_HEADER } from '../ws'
import { ViteDevServer } from '..'
import { Connect } from 'types/connect'
import { HttpProxy } from 'types/http-proxy'
import chalk from 'chalk'

const debug = createDebugger('vite:proxy')

Expand Down Expand Up @@ -42,6 +43,13 @@ export function proxyMiddleware({
opts = { target: opts } as ProxyOptions
}
const proxy = httpProxy.createProxyServer(opts) as HttpProxy.Server

proxy.on('error', (err) => {
config.logger.error(`${chalk.red(`http proxy error:`)}\n${err.stack}`, {
timestamp: true
})
})

if (opts.configure) {
opts.configure(proxy, opts)
}
Expand Down

0 comments on commit 4ca20f2

Please sign in to comment.