Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PoC] ui5 serve: Proxy mode #229

Draft
wants to merge 4 commits into
base: v2
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Enforce public npm registry
registry = https://registry.npmjs.org/
package-lock=false
26 changes: 20 additions & 6 deletions lib/cli/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ serve.builder = function(cli) {
type: "string"
})
.option("h2", {
describe: "Shortcut for enabling the HTTP/2 protocol for the web server",
describe: "Enables HTTP/2 and HTTPS protocol for the web server",
default: false,
type: "boolean"
})
.option("simple-index", {
describe: "Use a simplified view for the server directory listing",
default: false,

})
.option("proxy", {
describe: "Whether or not to use a configured proxy",
type: "boolean"
})
.option("accept-remote-connections", {
Expand Down Expand Up @@ -84,7 +88,7 @@ serve.handler = async function(argv) {
let changePortIfInUse = false;

if (!port && tree.server && tree.server.settings) {
if (argv.h2) {
if (argv.h2 || argv.proxy) {
port = tree.server.settings.httpsPort;
} else {
port = tree.server.settings.httpPort;
Expand All @@ -93,33 +97,43 @@ serve.handler = async function(argv) {

if (!port) {
changePortIfInUse = true; // only change if port isn't explicitly set
if (argv.h2) {
if (argv.h2 || argv.proxy) {
port = 8443;
} else {
port = 8080;
}
}
let cdnUrl;
if (tree.server && tree.server.cdnUrl) {
if (tree.specVersion !== "2.2a") {
throw new Error(`Server configuration "cdnUrl" can only be used with specification version "2.2a". ` +
`But project ${tree.metadata.name} defines "${tree.specVersion}".`);
}
cdnUrl = tree.server.cdnUrl;
}

const serverConfig = {
port,
changePortIfInUse,
h2: argv.h2,
useProxy: argv.proxy,
simpleIndex: !!argv.simpleIndex,
acceptRemoteConnections: !!argv.acceptRemoteConnections,
cert: argv.h2 ? argv.cert : undefined,
key: argv.h2 ? argv.key : undefined,
sendSAPTargetCSP: !!argv.sapCspPolicies
sendSAPTargetCSP: !!argv.sapCspPolicies,
cdnUrl
};

if (serverConfig.h2) {
if (serverConfig.h2 || argv.proxy) {
const {key, cert} = await ui5Server.sslUtil.getSslCertificate(serverConfig.key, serverConfig.cert);
serverConfig.key = key;
serverConfig.cert = cert;
}

const {h2, port: actualPort} = await server.serve(tree, serverConfig);

const protocol = h2 ? "https" : "http";
const protocol = (h2 || argv.proxy) ? "https" : "http";
let browserUrl = protocol + "://localhost:" + actualPort;
console.log("Server started");
console.log("URL: " + browserUrl);
Expand Down
Loading