Skip to content

Commit

Permalink
chore: revert vitejs#10196 until Vite 4 (vitejs#10574)
Browse files Browse the repository at this point in the history
This reverts commit f328f61.
  • Loading branch information
patak-dev committed Oct 21, 2022
1 parent e0463bd commit 07c0336
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/guide/api-javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/api-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 4 additions & 5 deletions packages/vite/src/node/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -95,7 +94,7 @@ export async function resolveHttpServer(
{ proxy }: CommonServerOptions,
app: Connect.Server,
httpsOptions?: HttpsServerOptions
): Promise<HttpServer | Http2SecureServer> {
): Promise<HttpServer> {
if (!httpsOptions) {
const { createServer } = await import('node:http')
return createServer(app)
Expand All @@ -117,7 +116,7 @@ export async function resolveHttpServer(
},
// @ts-expect-error TODO: is this correct?
app
)
) as unknown as HttpServer
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -186,7 +185,7 @@ export async function httpServerStart(
}

export function setClientErrorHandler(
server: HttpServer | Http2SecureServer,
server: HttpServer,
logger: Logger
): void {
server.on('clientError', (err, socket) => {
Expand Down
5 changes: 2 additions & 3 deletions packages/vite/src/node/preview.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
*/
Expand All @@ -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>

Expand Down
5 changes: 2 additions & 3 deletions packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -693,7 +692,7 @@ async function startServer(
}
}

function createServerCloseFn(server: http.Server | Http2SecureServer | null) {
function createServerCloseFn(server: http.Server | null) {
if (!server) {
return () => {}
}
Expand Down
3 changes: 1 addition & 2 deletions packages/vite/src/node/server/middlewares/proxy.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -31,7 +30,7 @@ export interface ProxyOptions extends HttpProxy.ServerOptions {
}

export function proxyMiddleware(
httpServer: http.Server | Http2SecureServer | null,
httpServer: http.Server | null,
options: NonNullable<CommonServerOptions['proxy']>,
config: ResolvedConfig
): Connect.NextHandleFunction {
Expand Down
3 changes: 1 addition & 2 deletions packages/vite/src/node/server/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -79,7 +78,7 @@ const wsServerEvents = [
]

export function createWebSocketServer(
server: Server | Http2SecureServer | null,
server: Server | null,
config: ResolvedConfig,
httpsOptions?: HttpsServerOptions
): WebSocketServer {
Expand Down

0 comments on commit 07c0336

Please sign in to comment.