orc-scripts 5.0.0-dev.0 → 5.0.0-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orc-scripts",
3
- "version": "5.0.0-dev.0",
3
+ "version": "5.0.0-dev.1",
4
4
  "description": "Scripts toolbox for Orckestra",
5
5
  "type": "commonjs",
6
6
  "bin": {
@@ -1,5 +1,7 @@
1
1
  const DevServer = require("webpack-dev-server");
2
2
  const webpack = require("webpack");
3
+ const path = require("path");
4
+ const fs = require("fs");
3
5
 
4
6
  const HOST = process.env.HOSTNAME || "localhost";
5
7
 
@@ -7,6 +9,42 @@ const args = process.argv.slice(2);
7
9
  const argPort = args.indexOf("--port") !== -1 ? args[args.indexOf("--port") + 1] : null;
8
10
  const PORT = argPort || process.env.PORT || 5000;
9
11
 
12
+ const findSslPasswordFromParametersFile = (certFile) => {
13
+ // reference: https://hals.app/blog/recursively-read-parent-folder-nodejs/
14
+
15
+ let parentDirectory = path.dirname(certFile);
16
+ while (fs.existsSync(parentDirectory)) {
17
+ console.log("Looking for certificate password in: " + parentDirectory)
18
+ const fileToFindPath = path.join(parentDirectory, "parameters.dev.xml");
19
+ if (fs.existsSync(fileToFindPath)) {
20
+ const fileContent = fs.readFileSync(fileToFindPath, "utf8");
21
+
22
+ // Using regex to parse the XML to avoid adding a dependency on an XML package
23
+
24
+ const matchResult = /<param\s+name="SSL_CertificatePfxPassword"\s+value="(?<Value>[^"]+)"\s*\/>/.exec(fileContent);
25
+ if (matchResult && matchResult.groups && matchResult.groups['Value']) {
26
+ console.log("Certificate password found");
27
+ return matchResult.groups['Value'];
28
+ }
29
+
30
+ console.warn("Could not find SSL_CertificatePfxPassword in file " + fileToFindPath)
31
+ return null;
32
+ }
33
+
34
+ // The trick is here:
35
+ // Using path.dirname() of a directory returns the parent directory!
36
+ const parentDirname = path.dirname(parentDirectory);
37
+ // But only to a certain point (file system root) (So to avoid infinite loops lets stop here)
38
+ if (parentDirectory === parentDirname) {
39
+ return null;
40
+ }
41
+
42
+ parentDirectory = parentDirname;
43
+ }
44
+
45
+ return null;
46
+ }
47
+
10
48
  const config = require("../config/webpack.config.js");
11
49
  const options = {
12
50
  historyApiFallback: true,
@@ -19,13 +57,20 @@ const options = {
19
57
  },
20
58
  };
21
59
 
22
- if (HOST !== "localhost") {
23
- options.public = HOST;
24
- }
25
60
  if (HOST !== "localhost" || args.indexOf("--https") !== -1 || process.env.HTTPS) {
26
61
  options.server = 'https';
27
62
  }
28
63
 
64
+ if (options.server === 'https' && process.env.SSL_CERT_PATH) {
65
+ options.server = {
66
+ type: 'https',
67
+ options: {
68
+ pfx: process.env.SSL_CERT_PATH,
69
+ passphrase: process.env.SSL_CERT_PASSWORD || findSslPasswordFromParametersFile(process.env.SSL_CERT_PATH),
70
+ },
71
+ }
72
+ }
73
+
29
74
  const compiler = webpack(config);
30
75
 
31
76
  const server = new DevServer(options, compiler);