@redhat-cloud-services/frontend-components-config-utilities 2.0.2 → 2.1.0

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.
@@ -43,7 +43,7 @@ module.exports = ({
43
43
 
44
44
  const { dependencies, insights } = require(resolve(root, './package.json')) || {};
45
45
  const appName = moduleName || (insights && jsVarName(insights.appname));
46
- const filename = `${appName}.${useFileHash ? `[contenthash].` : ''}js`;
46
+ const filename = `${appName}.${useFileHash ? `[fullhash].` : ''}js`;
47
47
 
48
48
  let sharedDeps = Object.entries(include)
49
49
  .filter(([key]) => dependencies[key] && !exclude.includes(key))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redhat-cloud-services/frontend-components-config-utilities",
3
- "version": "2.0.2",
3
+ "version": "2.1.0",
4
4
  "description": "Utilities for shared config used in RedHat Cloud Services project.",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
package/proxy.js CHANGED
@@ -16,6 +16,68 @@ const { registerChrome } = require('./standalone/services/default/chrome');
16
16
 
17
17
  const defaultReposDir = path.join(__dirname, 'repos');
18
18
 
19
+ const checkLocalAppHost = (appName, hostUrl, port) => {
20
+ const check = execSync(`curl --max-time 5 --silent --head ${hostUrl} | awk '/^HTTP/{print $2}'`).toString().trim();
21
+
22
+ if (check !== '200') {
23
+ console.error('\n' + appName[0].toUpperCase() + appName.substring(1) + ' is not running or available via ' + hostUrl);
24
+ console.log(
25
+ '\nMake sure to run `npm run start -- --port=' +
26
+ port +
27
+ '` in the ' +
28
+ appName +
29
+ " application directory to start it's webpack dev server and the bundle is built.\n"
30
+ );
31
+
32
+ return false;
33
+ } else {
34
+ return true;
35
+ }
36
+ };
37
+
38
+ const buildRoutes = (routes, target) =>
39
+ Object.entries(routes || {}).map(([route, redirect]) => {
40
+ const currTarget = redirect.host || redirect;
41
+ delete redirect.host;
42
+ return {
43
+ context: (path) => path.includes(route),
44
+ target: currTarget === 'PORTAL_BACKEND_MARKER' ? target : currTarget,
45
+ secure: false,
46
+ changeOrigin: true,
47
+ autoRewrite: true,
48
+ ws: true,
49
+ onProxyReq: cookieTransform,
50
+ ...(currTarget === 'PORTAL_BACKEND_MARKER' && { router }),
51
+ ...(typeof redirect === 'object' ? redirect : {}),
52
+ };
53
+ });
54
+
55
+ const buildLocalAppRoutes = (localApps, defaultLocalAppHost, target) =>
56
+ buildRoutes(
57
+ (!Array.isArray(localApps) ? localApps.split(',') : localApps).reduce((acc, curr) => {
58
+ const [appName, appConfig] = (curr || '').split(':');
59
+ const [appPort = 8003, protocol = 'http'] = appConfig.split('~');
60
+ const appUrl = `${protocol}://${defaultLocalAppHost}:${appPort}`;
61
+
62
+ if (checkLocalAppHost(appName, appUrl, appPort)) {
63
+ console.log('Creating app proxy routes for: ' + appName + ' to ' + appUrl);
64
+
65
+ return {
66
+ ...acc,
67
+ [`/apps/${appName}`]: {
68
+ host: appUrl,
69
+ },
70
+ [`/preview/apps/${appName}`]: {
71
+ host: appUrl,
72
+ },
73
+ };
74
+ } else {
75
+ process.exit();
76
+ }
77
+ }, {}),
78
+ target
79
+ );
80
+
19
81
  module.exports = ({
20
82
  env = 'ci-beta',
21
83
  customProxy = [],
@@ -39,9 +101,12 @@ module.exports = ({
39
101
  bounceProd = false,
40
102
  useAgent = true,
41
103
  useDevBuild = true,
104
+ localApps = process.env.LOCAL_APPS,
42
105
  }) => {
43
106
  const proxy = [];
44
107
  const majorEnv = env.split('-')[0];
108
+ const defaultLocalAppHost = process.env.LOCAL_APP_HOST || majorEnv + '.foo.redhat.com';
109
+
45
110
  if (target === '') {
46
111
  target += 'https://';
47
112
  if (!['prod', 'stage'].includes(majorEnv)) {
@@ -86,24 +151,11 @@ module.exports = ({
86
151
 
87
152
  if (routes) {
88
153
  routes = routes.routes || routes;
89
- console.log('Making proxy from SPANDX routes');
90
- proxy.push(
91
- ...Object.entries(routes || {}).map(([route, redirect]) => {
92
- const currTarget = redirect.host || redirect;
93
- delete redirect.host;
94
- return {
95
- context: (path) => path.includes(route),
96
- target: currTarget === 'PORTAL_BACKEND_MARKER' ? target : currTarget,
97
- secure: false,
98
- changeOrigin: true,
99
- autoRewrite: true,
100
- ws: true,
101
- onProxyReq: cookieTransform,
102
- ...(currTarget === 'PORTAL_BACKEND_MARKER' && { router }),
103
- ...(typeof redirect === 'object' ? redirect : {}),
104
- };
105
- })
106
- );
154
+ proxy.push(...buildRoutes(routes, target));
155
+ }
156
+
157
+ if (localApps?.length > 0) {
158
+ proxy.push(...buildLocalAppRoutes(localApps, defaultLocalAppHost, target));
107
159
  }
108
160
 
109
161
  if (customProxy) {