Skip to content

Commit

Permalink
feat(ui5-middleware-serveframework): allow usage with self signed cer…
Browse files Browse the repository at this point in the history
…tificates (#1073)

* feat: use serveframework with self signed certificates

* fix: update

* fix: update suggested changes
  • Loading branch information
marianfoo authored Sep 10, 2024
1 parent c574f80 commit 089fdbc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
2 changes: 2 additions & 0 deletions packages/ui5-middleware-serveframework/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ npm install ui5-middleware-serveframework --save-dev
Name of environment variable that contains ui5 version (in case you want to override framework version from ui5.yaml)
- `envFilePath`: *`string`*, default: `./.env`
Path to file with environment variables
- `strictSSL`: `boolean`
Ignore strict SSL checks. Default value `true`.

## Usage

Expand Down
29 changes: 19 additions & 10 deletions packages/ui5-middleware-serveframework/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const yaml = require("js-yaml");

const etag = require("etag");
const fresh = require("fresh");
const { Agent: HttpsAgent } = require("https");

/**
* Serves the built variant of the current framework
Expand All @@ -22,6 +23,7 @@ module.exports = async ({ log, options, middlewareUtil }) => {
// provide a set of default runtime options
const effectiveOptions = {
debug: false,
strictSSL: true,
};
// config-time options from ui5.yaml for cfdestination take precedence
if (options.configuration) {
Expand Down Expand Up @@ -73,16 +75,23 @@ module.exports = async ({ log, options, middlewareUtil }) => {

// support for coporate proxies
const { getProxyForUrl } = await import("proxy-from-env");
const proxyUrl = getProxyForUrl(baseUrl);
const { HttpsProxyAgent } = await import("https-proxy-agent");
const agent = proxyUrl ? new HttpsProxyAgent(proxyUrl) : undefined;
effectiveOptions.debug && log.info(`[${baseUrl}] Proxy: ${proxyUrl ? proxyUrl : "n/a"}`);
// detect and configure proxy agent
const proxyUrl = getProxyForUrl(baseUrl);
const agentOptions = { rejectUnauthorized: effectiveOptions.strictSSL };

const agent = proxyUrl ? new HttpsProxyAgent(proxyUrl, agentOptions) : new HttpsAgent(agentOptions);

if (effectiveOptions.debug) {
log.info(`[${baseUrl}] Proxy: ${proxyUrl || "n/a"}, strictSSL: ${effectiveOptions.strictSSL}`);
}

// fetch the version information for the concrete version from CDN
const fetch = (await import("node-fetch")).default;
await fetch(`${baseUrl}/${frameworkVersion}/resources/sap-ui-version.json`, { agent })
.then((res) => res.json())
.then((json) => writeFile(versionInfoFile, JSON.stringify(json), { encoding: "utf-8" }));
const versionUrl = `${baseUrl}/${frameworkVersion}/resources/sap-ui-version.json`;
const response = await fetch(versionUrl, { agent });
const versionInfo = await response.json();
await writeFile(versionInfoFile, JSON.stringify(versionInfo), { encoding: "utf-8" });
}
const versionInfo = JSON.parse(await readFile(versionInfoFile, { encoding: "utf-8" }));

Expand Down Expand Up @@ -110,11 +119,11 @@ module.exports = async ({ log, options, middlewareUtil }) => {
version: frameworkVersion,
},
undefined,
2
2,
),
{
encoding: "utf-8",
}
},
);

// create a ui5.yaml to list all librar
Expand Down Expand Up @@ -165,11 +174,11 @@ module.exports = async ({ log, options, middlewareUtil }) => {
},
},
undefined,
2
2,
),
{
encoding: "utf-8",
}
},
);

// create a project graph with all library dependencies
Expand Down

0 comments on commit 089fdbc

Please sign in to comment.