Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import portscanner from "portscanner";
import MiddlewareManager from "./middleware/MiddlewareManager.js";
import {createReaderCollection} from "@ui5/fs/resourceFactory";
import ReaderCollectionPrioritized from "@ui5/fs/ReaderCollectionPrioritized";
import {getLogger} from "@ui5/logger";

const log = getLogger("server");
/**
* @public
* @module @ui5/server
Expand Down Expand Up @@ -178,6 +180,12 @@ export async function serve(graph, {
await middlewareManager.applyMiddleware(app);

if (h2) {
const nodeVersion = parseInt(process.versions.node.split(".")[0], 10);
if (nodeVersion >= 24) {
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.");
process.exit(1);
}

app = await _addSsl({app, key, cert});
}

Expand Down
84 changes: 48 additions & 36 deletions test/lib/server/h2.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,57 @@ import path from "node:path";
let request;
let server;

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

const graph = await graphFromPackageDependencies({
cwd: "./test/fixtures/application.a"
});
const sslPath = path.join(process.cwd(), "./test/fixtures/ssl/");
const {key, cert} = await getSslCertificate(
path.join(sslPath, "server.key"),
path.join(sslPath, "server.crt"),
);
server = await serve(graph, {
port: 3366,
h2: true,
key,
cert
// Withe Node.js 24 and later, the HTTP parser is missing, which breaks the HTTP/2 support in the spdy package.
// Tests need to be NodeJs version agnostic.
if (nodeVersion < 24) {
// Start server before running tests
test.before(async (t) => {
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0";

const graph = await graphFromPackageDependencies({
cwd: "./test/fixtures/application.a"
});
const sslPath = path.join(process.cwd(), "./test/fixtures/ssl/");
const {key, cert} = await getSslCertificate(
path.join(sslPath, "server.key"),
path.join(sslPath, "server.crt"),
);
server = await serve(graph, {
port: 3366,
h2: true,
key,
cert
});
request = supertest("https://localhost:3366");
});
request = supertest("https://localhost:3366");
});

test.after(() => {
return new Promise((resolve, reject) => {
server.close((error) => {
if (error) {
reject(error);
} else {
resolve();
}
test.after(() => {
return new Promise((resolve, reject) => {
server.close((error) => {
if (error) {
reject(error);
} else {
resolve();
}
});
});
});
});

test("Get resource from application.a (/index.html)", async (t) => {
const res = await request.get("/index.html");
if (res.error) {
t.fail(res.error.text);
}
t.is(res.statusCode, 200, "Correct HTTP status code");
t.regex(res.headers["content-type"], /html/, "Correct content type");
t.regex(res.text, /<title>Application A<\/title>/, "Correct response");
});
test("Get resource from application.a (/index.html)", async (t) => {
const res = await request.get("/index.html");
if (res.error) {
t.fail(res.error.text);
}
t.is(res.statusCode, 200, "Correct HTTP status code");
t.regex(res.headers["content-type"], /html/, "Correct content type");
t.regex(res.text, /<title>Application A<\/title>/, "Correct response");
});
} else {
test("HTTP Parser is missing", async (t) => {
await t.throwsAsync(async () => {
await import("spdy");
});
});
}