diff --git a/docs/guide/api-javascript.md b/docs/guide/api-javascript.md index 2f32b2cba10820..199507bc85b29e 100644 --- a/docs/guide/api-javascript.md +++ b/docs/guide/api-javascript.md @@ -72,7 +72,7 @@ interface ViteDevServer { * Native Node http server instance. * Will be null in middleware mode. */ - httpServer: http.Server | Http2SecureServer | null + httpServer: http.Server | null /** * Chokidar watcher instance. * https://github.com/paulmillr/chokidar#api diff --git a/docs/guide/api-plugin.md b/docs/guide/api-plugin.md index 7623437c4fa471..c18c6daca3263f 100644 --- a/docs/guide/api-plugin.md +++ b/docs/guide/api-plugin.md @@ -307,7 +307,7 @@ Vite plugins can also provide hooks that serve Vite-specific purposes. These hoo ### `configurePreviewServer` -- **Type:** `(server: { middlewares: Connect.Server, httpServer: http.Server | Http2SecureServer }) => (() => void) | void | Promise<(() => void) | void>` +- **Type:** `(server: { middlewares: Connect.Server, httpServer: http.Server }) => (() => void) | void | Promise<(() => void) | void>` - **Kind:** `async`, `sequential` Same as [`configureServer`](/guide/api-plugin.html#configureserver) but for the preview server. It provides the [connect](https://github.com/senchalabs/connect) server and its underlying [http server](https://nodejs.org/api/http.html). Similarly to `configureServer`, the `configurePreviewServer` hook is called before other middlewares are installed. If you want to inject a middleware **after** other middlewares, you can return a function from `configurePreviewServer`, which will be called after internal middlewares are installed: diff --git a/packages/vite/src/node/http.ts b/packages/vite/src/node/http.ts index 468af5afaee7b4..c77f5ec664ba3c 100644 --- a/packages/vite/src/node/http.ts +++ b/packages/vite/src/node/http.ts @@ -5,7 +5,6 @@ import type { OutgoingHttpHeaders as HttpServerHeaders } from 'node:http' import type { ServerOptions as HttpsServerOptions } from 'node:https' -import type { Http2SecureServer } from 'node:http2' import type { Connect } from 'dep-types/connect' import colors from 'picocolors' import { isObject } from './utils' @@ -95,7 +94,7 @@ export async function resolveHttpServer( { proxy }: CommonServerOptions, app: Connect.Server, httpsOptions?: HttpsServerOptions -): Promise { +): Promise { if (!httpsOptions) { const { createServer } = await import('node:http') return createServer(app) @@ -117,7 +116,7 @@ export async function resolveHttpServer( }, // @ts-expect-error TODO: is this correct? app - ) + ) as unknown as HttpServer } } @@ -150,7 +149,7 @@ function readFileIfExists(value?: string | Buffer | any[]) { } export async function httpServerStart( - httpServer: HttpServer | Http2SecureServer, + httpServer: HttpServer, serverOptions: { port: number strictPort: boolean | undefined @@ -186,7 +185,7 @@ export async function httpServerStart( } export function setClientErrorHandler( - server: HttpServer | Http2SecureServer, + server: HttpServer, logger: Logger ): void { server.on('clientError', (err, socket) => { diff --git a/packages/vite/src/node/preview.ts b/packages/vite/src/node/preview.ts index 6073ca1606c6b7..d17fc0845326dc 100644 --- a/packages/vite/src/node/preview.ts +++ b/packages/vite/src/node/preview.ts @@ -1,6 +1,5 @@ import path from 'node:path' import type * as http from 'node:http' -import type { Http2SecureServer } from 'node:http2' import sirv from 'sirv' import connect from 'connect' import type { Connect } from 'dep-types/connect' @@ -52,7 +51,7 @@ export interface PreviewServer { /** * native Node http server instance */ - httpServer: http.Server | Http2SecureServer + httpServer: http.Server /** * The resolved urls Vite prints on the CLI */ @@ -67,7 +66,7 @@ export type PreviewServerHook = ( this: void, server: { middlewares: Connect.Server - httpServer: http.Server | Http2SecureServer + httpServer: http.Server } ) => (() => void) | void | Promise<(() => void) | void> diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index 485353f3b982eb..5e8296e5ad3aad 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -2,7 +2,6 @@ import fs from 'node:fs' import path from 'node:path' import type * as net from 'node:net' import type * as http from 'node:http' -import type { Http2SecureServer } from 'node:http2' import { performance } from 'node:perf_hooks' import connect from 'connect' import corsMiddleware from 'cors' @@ -183,7 +182,7 @@ export interface ViteDevServer { * native Node http server instance * will be null in middleware mode */ - httpServer: http.Server | Http2SecureServer | null + httpServer: http.Server | null /** * chokidar watcher instance * https://github.com/paulmillr/chokidar#api @@ -693,7 +692,7 @@ async function startServer( } } -function createServerCloseFn(server: http.Server | Http2SecureServer | null) { +function createServerCloseFn(server: http.Server | null) { if (!server) { return () => {} } diff --git a/packages/vite/src/node/server/middlewares/proxy.ts b/packages/vite/src/node/server/middlewares/proxy.ts index 9e786b801f602f..fcd89707fe0204 100644 --- a/packages/vite/src/node/server/middlewares/proxy.ts +++ b/packages/vite/src/node/server/middlewares/proxy.ts @@ -1,5 +1,4 @@ import type * as http from 'node:http' -import type { Http2SecureServer } from 'node:http2' import type * as net from 'node:net' import httpProxy from 'http-proxy' import type { Connect } from 'dep-types/connect' @@ -31,7 +30,7 @@ export interface ProxyOptions extends HttpProxy.ServerOptions { } export function proxyMiddleware( - httpServer: http.Server | Http2SecureServer | null, + httpServer: http.Server | null, options: NonNullable, config: ResolvedConfig ): Connect.NextHandleFunction { diff --git a/packages/vite/src/node/server/ws.ts b/packages/vite/src/node/server/ws.ts index e7d78fd9d942d4..cb8555122b6840 100644 --- a/packages/vite/src/node/server/ws.ts +++ b/packages/vite/src/node/server/ws.ts @@ -2,7 +2,6 @@ import type { Server } from 'node:http' import { STATUS_CODES } from 'node:http' import type { ServerOptions as HttpsServerOptions } from 'node:https' import { createServer as createHttpsServer } from 'node:https' -import type { Http2SecureServer } from 'node:http2' import type { Socket } from 'node:net' import colors from 'picocolors' import type { ServerOptions, WebSocket as WebSocketRaw } from 'ws' @@ -79,7 +78,7 @@ const wsServerEvents = [ ] export function createWebSocketServer( - server: Server | Http2SecureServer | null, + server: Server | null, config: ResolvedConfig, httpsOptions?: HttpsServerOptions ): WebSocketServer {