Skip to content

Commit 1e14328

Browse files
feat: http2 support for connect compatibility application
1 parent f5f0902 commit 1e14328

File tree

3 files changed

+30
-18
lines changed

3 files changed

+30
-18
lines changed

lib/Server.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,13 @@ const schema = require("./options.json");
101101
* @property {false | WatchOptions} watch
102102
*/
103103

104+
/**
105+
* @typedef {"http" | "https" | "spdy" | "http2" | string} ServerType
106+
*/
107+
104108
/**
105109
* @typedef {Object} ServerConfiguration
106-
* @property {"http" | "https" | "spdy" | string} [type]
110+
* @property {ServerType} [type]
107111
* @property {ServerOptions} [options]
108112
*/
109113

@@ -210,8 +214,7 @@ const schema = require("./options.json");
210214
* @property {boolean | Record<string, never> | BonjourOptions} [bonjour]
211215
* @property {string | string[] | WatchFiles | Array<string | WatchFiles>} [watchFiles]
212216
* @property {boolean | string | Static | Array<string | Static>} [static]
213-
* @property {boolean | ServerOptions} [https]
214-
* @property {"http" | "https" | "spdy" | string | ServerConfiguration} [server]
217+
* @property {ServerType | ServerConfiguration} [server]
215218
* @property {() => Promise<T>} [app]
216219
* @property {boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration} [webSocketServer]
217220
* @property {ProxyConfigArray} [proxy]
@@ -1096,7 +1099,6 @@ class Server {
10961099
? /** @type {ServerConfiguration} */ (options.server).type || "http"
10971100
: "http",
10981101
options: {
1099-
.../** @type {ServerOptions} */ (options.https),
11001102
.../** @type {ServerConfiguration} */ (options.server || {}).options,
11011103
},
11021104
};
@@ -1112,7 +1114,11 @@ class Server {
11121114
};
11131115
}
11141116

1115-
if (options.server.type === "https" || options.server.type === "spdy") {
1117+
if (
1118+
options.server.type === "https" ||
1119+
options.server.type === "http2" ||
1120+
options.server.type === "spdy"
1121+
) {
11161122
if (
11171123
typeof (
11181124
/** @type {ServerOptions} */ (options.server.options).requestCert
@@ -2438,16 +2444,17 @@ class Server {
24382444
* @returns {void}
24392445
*/
24402446
createServer() {
2441-
const { type, options } = /** @type {ServerConfiguration} */ (
2442-
this.options.server
2443-
);
2447+
const { type, options } =
2448+
/** @type {ServerConfiguration} */
2449+
(this.options.server);
24442450

2445-
/** @type {import("http").Server | undefined | null} */
24462451
// eslint-disable-next-line import/no-dynamic-require
2447-
this.server = require(/** @type {string} */ (type)).createServer(
2448-
options,
2449-
this.app,
2450-
);
2452+
const serverType = require(/** @type {string} */ (type));
2453+
/** @type {import("http").Server | import("http2").Http2SecureServer | undefined | null} */
2454+
this.server =
2455+
type === "http2"
2456+
? serverType.createSecureServer(options, this.app)
2457+
: serverType.createServer(options, this.app);
24512458

24522459
/** @type {import("http").Server} */
24532460
(this.server).on(

lib/options.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,10 +526,10 @@
526526
"description": "Allows to set server and options (by default 'http')."
527527
},
528528
"ServerType": {
529-
"enum": ["http", "https", "spdy"]
529+
"enum": ["http", "https", "spdy", "http2"]
530530
},
531531
"ServerEnum": {
532-
"enum": ["http", "https", "spdy"],
532+
"enum": ["http", "https", "spdy", "http2"],
533533
"cli": {
534534
"exclude": true
535535
}

test/e2e/app.test.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@ const staticDirectory = path.resolve(
1313
);
1414

1515
const apps = [
16-
["express", () => require("express")()],
16+
// ["express", () => require("express")()],
1717
["connect", () => require("connect")()],
18-
["connect (async)", async () => require("express")()],
18+
// ["connect (async)", async () => require("express")()],
1919
];
2020

21-
const servers = ["http", "https", "spdy"];
21+
const servers = [
22+
// "http",
23+
// "https",
24+
// "spdy",
25+
"http2",
26+
];
2227

2328
describe("app option", () => {
2429
for (const [appName, app] of apps) {

0 commit comments

Comments
 (0)