@@ -25,6 +25,7 @@ import type {
2525 DevServerStaticItem ,
2626 DevServerWebSocketURL ,
2727} from '@rspack/core' ;
28+ import type { RequestHandler } from 'http-proxy-middleware' ;
2829import { devMiddleware } from '@rspack/dev-middleware' ;
2930import type {
3031 HandleFunction ,
@@ -64,7 +65,6 @@ import type {
6465 OverlayMessageOptions ,
6566 Port ,
6667 Request ,
67- RequestHandler ,
6868 Response ,
6969 ServerConfiguration ,
7070 ServerOptions ,
@@ -186,7 +186,7 @@ class Server<
186186 name : string | symbol ;
187187 listener : ( ...args : EXPECTED_ANY [ ] ) => void ;
188188 } [ ] ;
189- webSocketProxies : RequestHandler [ ] ;
189+ webSocketProxies : NextHandleFunction [ ] ;
190190 sockets : Socket [ ] ;
191191 currentHash : string | undefined ;
192192 isTlsServer = false ;
@@ -1445,14 +1445,14 @@ class Server<
14451445
14461446 // Proxy WebSocket without the initial http request
14471447 // https://github.com/chimurai/http-proxy-middleware#external-websocket-upgrade
1448- const webSocketProxies = this . webSocketProxies as RequestHandler [ ] ;
1448+ const webSocketProxies = this . webSocketProxies as NextHandleFunction [ ] ;
14491449
14501450 for ( const webSocketProxy of webSocketProxies ) {
14511451 ( this . server as S ) . on (
14521452 'upgrade' ,
14531453 (
1454- webSocketProxy as RequestHandler & {
1455- upgrade : NonNullable < RequestHandler [ 'upgrade' ] > ;
1454+ webSocketProxy as NextHandleFunction & {
1455+ upgrade : RequestHandler [ 'upgrade' ] ;
14561456 }
14571457 ) . upgrade ,
14581458 ) ;
@@ -1729,11 +1729,13 @@ class Server<
17291729 } ) ;
17301730
17311731 if ( this . options . proxy ) {
1732- const { createProxyMiddleware } = require ( 'http-proxy-middleware' ) ;
1732+ const { createProxyMiddleware } = await import (
1733+ /* webpackChunkName: "http-proxy-middleware" */ 'http-proxy-middleware'
1734+ ) ;
17331735
17341736 const getProxyMiddleware = (
17351737 proxyConfig : DevServerProxyConfigArrayItem ,
1736- ) : RequestHandler | undefined => {
1738+ ) : NextHandleFunction | undefined => {
17371739 const { context, ...proxyOptions } = proxyConfig ;
17381740 const pathFilter = proxyOptions . pathFilter ?? context ;
17391741
@@ -1746,7 +1748,9 @@ class Server<
17461748 }
17471749
17481750 if ( proxyOptions . target || proxyOptions . router ) {
1749- return createProxyMiddleware ( proxyOptions ) ;
1751+ return createProxyMiddleware (
1752+ proxyOptions as Parameters < typeof createProxyMiddleware > [ 0 ] ,
1753+ ) ;
17501754 }
17511755
17521756 util . deprecate (
@@ -1774,7 +1778,7 @@ class Server<
17741778 * ]
17751779 */
17761780 for ( const proxyConfigOrCallback of this . options . proxy ) {
1777- let proxyMiddleware : RequestHandler | undefined ;
1781+ let proxyMiddleware : NextHandleFunction | undefined ;
17781782
17791783 let proxyConfig =
17801784 typeof proxyConfigOrCallback === 'function'
@@ -1941,7 +1945,7 @@ class Server<
19411945
19421946 for ( const i of middlewares ) {
19431947 if ( i . name === '@rspack/dev-middleware' ) {
1944- const item = i as MiddlewareObject | RequestHandler ;
1948+ const item = i as MiddlewareObject | NextHandleFunction ;
19451949
19461950 if ( typeof ( item as MiddlewareObject ) . middleware === 'undefined' ) {
19471951 ( item as MiddlewareObject ) . middleware =
0 commit comments