MCPcopy
hub / github.com/vitejs/vite / tryBindServer

Function tryBindServer

packages/vite/src/node/http.ts:190–214  ·  view source on GitHub ↗
(
  httpServer: HttpServer,
  port: number,
  host: string | undefined,
)

Source from the content-addressed store, hash-verified

188}
189
190async function tryBindServer(
191 httpServer: HttpServer,
192 port: number,
193 host: string | undefined,
194): Promise<
195 { success: true } | { success: false; error: NodeJS.ErrnoException }
196> {
197 return new Promise((resolve) => {
198 const onError = (e: NodeJS.ErrnoException) => {
199 httpServer.off('error', onError)
200 httpServer.off('listening', onListening)
201 resolve({ success: false, error: e })
202 }
203 const onListening = () => {
204 httpServer.off('error', onError)
205 httpServer.off('listening', onListening)
206 resolve({ success: true })
207 }
208
209 httpServer.on('error', onError)
210 httpServer.on('listening', onListening)
211
212 httpServer.listen(port, host)
213 })
214}
215
216const MAX_PORT = 65535
217

Callers 1

httpServerStartFunction · 0.85

Calls 2

onMethod · 0.65
listenMethod · 0.65

Tested by

no test coverage detected