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

Function startServer

packages/vite/src/node/server/index.ts:1092–1120  ·  view source on GitHub ↗
(
  server: ViteDevServer,
  hostname: Hostname,
  inlinePort?: number,
)

Source from the content-addressed store, hash-verified

1090}
1091
1092async function startServer(
1093 server: ViteDevServer,
1094 hostname: Hostname,
1095 inlinePort?: number,
1096): Promise<void> {
1097 const httpServer = server.httpServer
1098 if (!httpServer) {
1099 throw new Error('Cannot call server.listen in middleware mode.')
1100 }
1101
1102 const options = server.config.server
1103 const configPort = inlinePort ?? options.port
1104 // When using non strict port for the dev server, the running port can be different from the config one.
1105 // When restarting, the original port may be available but to avoid a switch of URL for the running
1106 // browser tabs, we enforce the previously used port, expect if the config port changed.
1107 const port =
1108 (!configPort || configPort === server._configServerPort
1109 ? server._currentServerPort
1110 : configPort) ?? DEFAULT_DEV_PORT
1111 server._configServerPort = configPort
1112
1113 const serverPort = await httpServerStart(httpServer, {
1114 port,
1115 strictPort: options.strictPort,
1116 host: hostname.host,
1117 logger: server.config.logger,
1118 })
1119 server._currentServerPort = serverPort
1120}
1121
1122export function createServerCloseFn(
1123 server: HttpServer | null,

Callers 2

listenFunction · 0.70
shortcuts.spec.tsFile · 0.50

Calls 1

httpServerStartFunction · 0.90

Tested by

no test coverage detected