Skip to content

Commit 71dd7af

Browse files
authored
[FIX] Log error in case UI5 Server uses HTTP/2 with Node 24 (#722)
JIRA: CPOUI5FOUNDATION-1070
1 parent 3464024 commit 71dd7af

File tree

2 files changed

+56
-36
lines changed

2 files changed

+56
-36
lines changed

lib/server.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import portscanner from "portscanner";
33
import MiddlewareManager from "./middleware/MiddlewareManager.js";
44
import {createReaderCollection} from "@ui5/fs/resourceFactory";
55
import ReaderCollectionPrioritized from "@ui5/fs/ReaderCollectionPrioritized";
6+
import {getLogger} from "@ui5/logger";
67

8+
const log = getLogger("server");
79
/**
810
* @public
911
* @module @ui5/server
@@ -178,6 +180,12 @@ export async function serve(graph, {
178180
await middlewareManager.applyMiddleware(app);
179181

180182
if (h2) {
183+
const nodeVersion = parseInt(process.versions.node.split(".")[0], 10);
184+
if (nodeVersion >= 24) {
185+
log.error("ERROR: With Node v24, usage of HTTP/2 is no longer supported. Please check https://github.com/SAP/ui5-tooling/issues/327 for updates.");
186+
process.exit(1);
187+
}
188+
181189
app = await _addSsl({app, key, cert});
182190
}
183191

test/lib/server/h2.js

Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,57 @@ import path from "node:path";
88
let request;
99
let server;
1010

11-
// Start server before running tests
12-
test.before(async (t) => {
13-
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0";
11+
const nodeVersion = parseInt(process.versions.node.split(".")[0], 10);
1412

15-
const graph = await graphFromPackageDependencies({
16-
cwd: "./test/fixtures/application.a"
17-
});
18-
const sslPath = path.join(process.cwd(), "./test/fixtures/ssl/");
19-
const {key, cert} = await getSslCertificate(
20-
path.join(sslPath, "server.key"),
21-
path.join(sslPath, "server.crt"),
22-
);
23-
server = await serve(graph, {
24-
port: 3366,
25-
h2: true,
26-
key,
27-
cert
13+
// Withe Node.js 24 and later, the HTTP parser is missing, which breaks the HTTP/2 support in the spdy package.
14+
// Tests need to be NodeJs version agnostic.
15+
if (nodeVersion < 24) {
16+
// Start server before running tests
17+
test.before(async (t) => {
18+
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0";
19+
20+
const graph = await graphFromPackageDependencies({
21+
cwd: "./test/fixtures/application.a"
22+
});
23+
const sslPath = path.join(process.cwd(), "./test/fixtures/ssl/");
24+
const {key, cert} = await getSslCertificate(
25+
path.join(sslPath, "server.key"),
26+
path.join(sslPath, "server.crt"),
27+
);
28+
server = await serve(graph, {
29+
port: 3366,
30+
h2: true,
31+
key,
32+
cert
33+
});
34+
request = supertest("https://localhost:3366");
2835
});
29-
request = supertest("https://localhost:3366");
30-
});
3136

32-
test.after(() => {
33-
return new Promise((resolve, reject) => {
34-
server.close((error) => {
35-
if (error) {
36-
reject(error);
37-
} else {
38-
resolve();
39-
}
37+
test.after(() => {
38+
return new Promise((resolve, reject) => {
39+
server.close((error) => {
40+
if (error) {
41+
reject(error);
42+
} else {
43+
resolve();
44+
}
45+
});
4046
});
4147
});
42-
});
4348

44-
test("Get resource from application.a (/index.html)", async (t) => {
45-
const res = await request.get("/index.html");
46-
if (res.error) {
47-
t.fail(res.error.text);
48-
}
49-
t.is(res.statusCode, 200, "Correct HTTP status code");
50-
t.regex(res.headers["content-type"], /html/, "Correct content type");
51-
t.regex(res.text, /<title>Application A<\/title>/, "Correct response");
52-
});
49+
test("Get resource from application.a (/index.html)", async (t) => {
50+
const res = await request.get("/index.html");
51+
if (res.error) {
52+
t.fail(res.error.text);
53+
}
54+
t.is(res.statusCode, 200, "Correct HTTP status code");
55+
t.regex(res.headers["content-type"], /html/, "Correct content type");
56+
t.regex(res.text, /<title>Application A<\/title>/, "Correct response");
57+
});
58+
} else {
59+
test("HTTP Parser is missing", async (t) => {
60+
await t.throwsAsync(async () => {
61+
await import("spdy");
62+
});
63+
});
64+
}

0 commit comments

Comments
 (0)