Skip to content

Commit b3a9c58

Browse files
authored
feat: migrate from connect to connect-next (#144)
1 parent 7bf5b45 commit b3a9c58

8 files changed

Lines changed: 42 additions & 78 deletions

File tree

docs/migrate-v1-to-v2.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ The minimum supported Node.js version is now `^20.19.0 || >=22.12.0`.
5757

5858
> Refer to the [http-proxy-middleware v3 migration guide](https://github.com/chimurai/http-proxy-middleware/blob/master/MIGRATION.md) for details.
5959
60-
### Default app now uses `connect`
60+
### Default app now uses `connect-next`
6161

6262
When `devServer.app` is omitted, `@rspack/dev-server` now creates a
63-
`connect` app instead of an Express app.
63+
`connect-next` app instead of an Express app.
6464

65-
The dev server only needs a minimal middleware pipeline. Connect provides the same `(req, res, next)` interface as Express while being significantly smaller and having fewer dependencies, making it a better fit for this use case.
65+
The dev server only needs a minimal middleware pipeline. [connect-next](https://github.com/rstackjs/connect-next) is an actively maintained fork of Connect that keeps the same `(req, res, next)` middleware interface while staying smaller than Express and having fewer dependencies.
6666

6767
If you relied on Express-only APIs on `devServer.app`, such as `app.get()`,
6868
`app.post()`, or `res.send()`, provide your own Express app explicitly:

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,12 @@
4545
]
4646
},
4747
"dependencies": {
48-
"@types/connect": "^3.4.38",
4948
"@types/connect-history-api-fallback": "^1.5.4",
5049
"@types/serve-index": "^1.9.4",
5150
"@types/serve-static": "^2.2.0",
5251
"@types/ws": "^8.18.1",
5352
"chokidar": "^3.6.0",
54-
"connect": "^3.7.0",
53+
"connect-next": "^4.0.0",
5554
"connect-history-api-fallback": "^2.0.0",
5655
"http-proxy-middleware": "^3.0.5",
5756
"ipaddr.js": "^2.3.0",

pnpm-lock.yaml

Lines changed: 9 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rslib.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export default defineConfig({
88
dts: true,
99
output: {
1010
externals: {
11-
connect: 'commonjs connect',
1211
'connect-history-api-fallback':
1312
'commonjs connect-history-api-fallback',
1413
'webpack-dev-middleware': 'commonjs webpack-dev-middleware',

src/server.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ const memoize = <T>(fn: FunctionReturning<T>): FunctionReturning<T> => {
142142
};
143143
};
144144

145-
const getConnect = memoize(() => require('connect'));
145+
const getConnect = async () => {
146+
const { connect } = await import('connect-next');
147+
return connect;
148+
};
146149
const getServeStatic = memoize(() => require('serve-static'));
147150

148151
const encodeOverlaySettings = (
@@ -1520,7 +1523,7 @@ class Server<
15201523
this.app = (
15211524
typeof this.options.app === 'function'
15221525
? await this.options.app()
1523-
: getConnect()()
1526+
: (await getConnect())()
15241527
) as A;
15251528
}
15261529

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export type { FSWatcher, WatchOptions };
2121
import type {
2222
Server as ConnectApplication,
2323
IncomingMessage as ConnectIncomingMessage,
24-
} from 'connect';
24+
} from 'connect-next';
2525
export type { ConnectApplication };
2626
import type { Options as ConnectHistoryApiFallbackOptions } from 'connect-history-api-fallback';
2727
export type { ConnectHistoryApiFallbackOptions };

tests/e2e/__snapshots__/app.test.js.snap

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// Rstest Snapshot v1
22

3-
exports[`app option > should work using "connect (async)" application and "http" server > should handle GET request to index route (/) > console messages 1`] = `
3+
exports[`app option > should work using "connect-next (async)" application and "http" server > should handle GET request to index route (/) > console messages 1`] = `
44
[
55
"[rspack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.",
66
"[HMR] Waiting for update signal from WDS...",
77
"Hey.",
88
]
99
`;
1010

11-
exports[`app option > should work using "connect (async)" application and "http" server > should handle GET request to index route (/) > page errors 1`] = `[]`;
11+
exports[`app option > should work using "connect-next (async)" application and "http" server > should handle GET request to index route (/) > page errors 1`] = `[]`;
1212

13-
exports[`app option > should work using "connect (async)" application and "http" server > should handle GET request to index route (/) > response status 1`] = `200`;
13+
exports[`app option > should work using "connect-next (async)" application and "http" server > should handle GET request to index route (/) > response status 1`] = `200`;
1414

15-
exports[`app option > should work using "connect (async)" application and "http" server > should handle GET request to index route (/) > response text 1`] = `
15+
exports[`app option > should work using "connect-next (async)" application and "http" server > should handle GET request to index route (/) > response text 1`] = `
1616
"
1717
<!DOCTYPE html>
1818
<html>
@@ -28,19 +28,19 @@ exports[`app option > should work using "connect (async)" application and "http"
2828
"
2929
`;
3030
31-
exports[`app option > should work using "connect" application and "http" server > should handle GET request to index route (/) > console messages 1`] = `
31+
exports[`app option > should work using "connect-next" application and "http" server > should handle GET request to index route (/) > console messages 1`] = `
3232
[
3333
"[rspack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.",
3434
"[HMR] Waiting for update signal from WDS...",
3535
"Hey.",
3636
]
3737
`;
3838
39-
exports[`app option > should work using "connect" application and "http" server > should handle GET request to index route (/) > page errors 1`] = `[]`;
39+
exports[`app option > should work using "connect-next" application and "http" server > should handle GET request to index route (/) > page errors 1`] = `[]`;
4040
41-
exports[`app option > should work using "connect" application and "http" server > should handle GET request to index route (/) > response status 1`] = `200`;
41+
exports[`app option > should work using "connect-next" application and "http" server > should handle GET request to index route (/) > response status 1`] = `200`;
4242
43-
exports[`app option > should work using "connect" application and "http" server > should handle GET request to index route (/) > response text 1`] = `
43+
exports[`app option > should work using "connect-next" application and "http" server > should handle GET request to index route (/) > response text 1`] = `
4444
"
4545
<!DOCTYPE html>
4646
<html>
@@ -56,19 +56,19 @@ exports[`app option > should work using "connect" application and "http" server
5656
"
5757
`;
5858
59-
exports[`app option > should work using "connect" application and "http2" server > should handle GET request to index route (/) > console messages 1`] = `
59+
exports[`app option > should work using "connect-next" application and "http2" server > should handle GET request to index route (/) > console messages 1`] = `
6060
[
6161
"[rspack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.",
6262
"[HMR] Waiting for update signal from WDS...",
6363
"Hey.",
6464
]
6565
`;
6666
67-
exports[`app option > should work using "connect" application and "http2" server > should handle GET request to index route (/) > page errors 1`] = `[]`;
67+
exports[`app option > should work using "connect-next" application and "http2" server > should handle GET request to index route (/) > page errors 1`] = `[]`;
6868
69-
exports[`app option > should work using "connect" application and "http2" server > should handle GET request to index route (/) > response status 1`] = `200`;
69+
exports[`app option > should work using "connect-next" application and "http2" server > should handle GET request to index route (/) > response status 1`] = `200`;
7070
71-
exports[`app option > should work using "connect" application and "http2" server > should handle GET request to index route (/) > response text 1`] = `
71+
exports[`app option > should work using "connect-next" application and "http2" server > should handle GET request to index route (/) > response text 1`] = `
7272
"
7373
<!DOCTYPE html>
7474
<html>
@@ -84,19 +84,19 @@ exports[`app option > should work using "connect" application and "http2" server
8484
"
8585
`;
8686
87-
exports[`app option > should work using "connect" application and "https" server > should handle GET request to index route (/) > console messages 1`] = `
87+
exports[`app option > should work using "connect-next" application and "https" server > should handle GET request to index route (/) > console messages 1`] = `
8888
[
8989
"[rspack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.",
9090
"[HMR] Waiting for update signal from WDS...",
9191
"Hey.",
9292
]
9393
`;
9494
95-
exports[`app option > should work using "connect" application and "https" server > should handle GET request to index route (/) > page errors 1`] = `[]`;
95+
exports[`app option > should work using "connect-next" application and "https" server > should handle GET request to index route (/) > page errors 1`] = `[]`;
9696
97-
exports[`app option > should work using "connect" application and "https" server > should handle GET request to index route (/) > response status 1`] = `200`;
97+
exports[`app option > should work using "connect-next" application and "https" server > should handle GET request to index route (/) > response status 1`] = `200`;
9898
99-
exports[`app option > should work using "connect" application and "https" server > should handle GET request to index route (/) > response text 1`] = `
99+
exports[`app option > should work using "connect-next" application and "https" server > should handle GET request to index route (/) > response text 1`] = `
100100
"
101101
<!DOCTYPE html>
102102
<html>

tests/e2e/app.test.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ const staticDirectory = path.resolve(
1212
'../fixtures/static-config/public',
1313
);
1414

15+
const createConnectNextApp = () =>
16+
import('connect-next').then(({ connect }) => connect());
17+
1518
const apps = [
1619
['express', () => require('express')(), 'http'],
1720
['express', () => require('express')(), 'https'],
18-
['connect', () => require('connect')(), 'http'],
19-
['connect', () => require('connect')(), 'https'],
20-
['connect', () => require('connect')(), 'http2'],
21-
['connect (async)', () => require('connect')(), 'http'],
21+
['connect-next', createConnectNextApp, 'http'],
22+
['connect-next', createConnectNextApp, 'https'],
23+
['connect-next', createConnectNextApp, 'http2'],
24+
['connect-next (async)', async () => createConnectNextApp(), 'http'],
2225
[
2326
'hono',
2427
() => new (require('hono').Hono)(),

0 commit comments

Comments
 (0)