@boomerang-io/webapp-spa-server 1.0.2-beta.0 → 1.1.0-beta.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.
Files changed (3) hide show
  1. package/README.md +11 -4
  2. package/index.js +74 -67
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -10,6 +10,9 @@ Provide a consistent way to deploy Boomerang React SPAs with client-side routing
10
10
  - Logging with [@boomerang-io/logger-middleware](https://github.com/boomerang-io/webapp-packages/src/packages/logger-middleware)
11
11
  - Cloud native health checking with [Cloud Native Health Connect](@cloudnative/health-connect)
12
12
  - New Relic monitoring
13
+ - Instana monitoring
14
+ - Google Analytics
15
+ - BeeHeard survey
13
16
 
14
17
  ## Design
15
18
 
@@ -60,15 +63,19 @@ The following env variables are assumed to exist either from a local `.env` file
60
63
  | :--------------------------: | :-----------------------------------------------------------------------: | :------------------: |
61
64
  | APP_ROOT | Root context of the application | string |
62
65
  | BUILD_DIR | directory relative to the exeuction where app files are located | string |
66
+ | PORT | Port for server to run on | number |
63
67
  | HTML_HEAD_INJECTED_DATA_KEYS | Environment variables to inject into the HTML document | comma delimited list |
64
68
  | HTML_HEAD_INJECTED_SCRIPTS | Scripts to inject into HTML document. Files need to be in the `BUILD_DIR` | comma delimited list |
65
- | NEW_RELIC_APP_NAME | App name for monitoring | string |
66
- | NEW_RELIC_LICENSE_KEY | License key for monitoring | string |
67
- | PORT | Port for server to run on | number |
69
+ | NEW_RELIC_APP_NAME | App name for New Relic monitoring | string |
70
+ | NEW_RELIC_LICENSE_KEY | License key for New Relic monitoring | string |
71
+ | INSTANA_REPORTING_URL | Reporting URL for Instana monitoring | string |
72
+ | INSTANA_KEY | License key for Instana monitoring | string |
73
+ | GA_SITE_ID | Site ID for Goolge Analytics | string |
74
+ | ENABLE_BEEHEARD_SURVEY | Enable BeeHeard survey | boolean |
68
75
 
69
76
  ## Defaults
70
77
 
71
- Some of the values, both config and environment variables have defaults in the server that make deploying to the IBM Cloud Private work out-of-the-box.
78
+ Some of the values, both config and environment variables have defaults in the server for deploying to the IBM Consulting Essentials platform.
72
79
 
73
80
  APP_ROOT
74
81
 
package/index.js CHANGED
@@ -36,8 +36,6 @@ function createBoomerangServer({
36
36
  NEW_RELIC_LICENSE_KEY,
37
37
  HTML_HEAD_INJECTED_SCRIPTS,
38
38
  BUILD_DIR = "build",
39
- GA_SITE_ID,
40
- ENABLE_BEEHEARD_SURVEY,
41
39
  } = process.env;
42
40
 
43
41
  // Monitoring
@@ -62,7 +60,11 @@ function createBoomerangServer({
62
60
  const helmet = require("helmet");
63
61
  app.use(
64
62
  helmet({
63
+ referrerPolicy: { policy: "strict-origin-when-cross-origin" },
65
64
  contentSecurityPolicy: false,
65
+ crossOriginEmbedderPolicy: false,
66
+ crossOriginOpenerPolicy: false,
67
+ crossOriginResourcePolicy: false,
66
68
  })
67
69
  );
68
70
  app.disable("x-powered-by");
@@ -94,18 +96,15 @@ function createBoomerangServer({
94
96
  })
95
97
  );
96
98
  appRouter.get("/*", (req, res) =>
97
- injectEnvDataAndScriptsIntoHTML(
99
+ injectEnvDataAndScriptsIntoHTML({
98
100
  res,
99
- BUILD_DIR,
100
- HTML_HEAD_INJECTED_DATA_KEYS,
101
- HTML_HEAD_INJECTED_SCRIPTS,
102
- APP_ROOT,
103
- GA_SITE_ID,
104
- ENABLE_BEEHEARD_SURVEY
105
- )
101
+ appRoot: APP_ROOT,
102
+ buildDir: BUILD_DIR,
103
+ injectedDataKeys: HTML_HEAD_INJECTED_DATA_KEYS,
104
+ injectedScripts: HTML_HEAD_INJECTED_SCRIPTS,
105
+ })
106
106
  );
107
107
  } else {
108
- logger.debug("1 - disableInjectHTMLHeadData: ", disableInjectHTMLHeadData);
109
108
  appRouter.use("/", express.static(path.join(process.cwd(), BUILD_DIR)));
110
109
  }
111
110
 
@@ -134,58 +133,8 @@ function createBoomerangServer({
134
133
  * @param {string} buildDir - build directory for building up path to index.html file
135
134
  * @param {string} injectedDataKeys - string of comma delimited values
136
135
  * @param {string} injectedScripts - string of comma delimited values
137
- * @param {string} appRoot - root context off app. Used for script injection
138
- * @param {string} gaSiteId - siteID to be injected on scripts to support GA
139
- * @param {string} baseLaunchUrl - base url to determine GA primaryCategory
140
- * @param {boolean} enableBeeheardSurvey - true/false value configured at helm to decide to insert survey script
141
136
  */
142
- function injectEnvDataAndScriptsIntoHTML(
143
- res,
144
- buildDir,
145
- injectedDataKeys,
146
- injectedScripts,
147
- appRoot,
148
- gaSiteId,
149
- enableBeeheardSurvey
150
- ) {
151
- /**
152
- * Create objects to be injected into application via the HEAD tag
153
- */
154
- // Build script for GA integration
155
- const headScripstGA = Boolean(gaSiteId)
156
- ? `<script type="text/javascript">
157
- window.idaPageIsSPA = true;
158
- window._ibmAnalytics = {
159
- settings: {
160
- name: "IBM_Services_Essentials",
161
- isSpa: true,
162
- tealiumProfileName: "ibm-web-app",
163
- },
164
- trustarc: {
165
- isCookiePreferencesButtonAlwaysOn: false,
166
- },
167
- };
168
- digitalData = {
169
- page: {
170
- pageInfo: {
171
- ibm: {
172
- siteID: '${gaSiteId}',
173
- }
174
- },
175
- category: {
176
- primaryCategory: 'PC100'
177
- }
178
- }
179
- };
180
- </script>
181
- <script src="//1.www.s81c.com/common/stats/ibm-common.js" type="text/javascript"></script>
182
- `
183
- : "";
184
-
185
- const headScriptBeeheardSurvey = Boolean(enableBeeheardSurvey)
186
- ? '<script async src="https://beeheard.dal1a.cirrus.ibm.com/survey/preconfig/HHPxpQgN.js"></script>'
187
- : "";
188
-
137
+ function injectEnvDataAndScriptsIntoHTML({ res, buildDir, appRoot, injectedDataKeys, injectedScripts }) {
189
138
  // Build up object of external data to append
190
139
  const headInjectedData = injectedDataKeys.split(",").reduce((acc, key) => {
191
140
  acc[key] = process.env[key];
@@ -193,7 +142,7 @@ function injectEnvDataAndScriptsIntoHTML(
193
142
  }, {});
194
143
 
195
144
  // Build up string of scripts to append, absolute path
196
- const headScriptsTags = injectedScripts
145
+ const localScriptTags = injectedScripts
197
146
  ? injectedScripts
198
147
  .split(",")
199
148
  .reduce((acc, currentValue) => `${acc}<script src="${appRoot}/${currentValue}"></script>`, "")
@@ -216,7 +165,6 @@ function injectEnvDataAndScriptsIntoHTML(
216
165
  * @param {Buffer} chunk
217
166
  * @return {string} replaced string with data interopolated
218
167
  */
219
- logger.debug("3 - GA script: ", headScripstGA);
220
168
  function addHeadData(chunk) {
221
169
  return chunk.toString().replace(
222
170
  "</head>",
@@ -225,12 +173,71 @@ function injectEnvDataAndScriptsIntoHTML(
225
173
  isJSON: true,
226
174
  })};
227
175
  </script>
228
- ${headScripstGA}
229
- ${headScriptBeeheardSurvey}
230
- ${headScriptsTags}
176
+ ${getBeeheardSurveyScripts()}
177
+ ${getGAScripts()}
178
+ ${getInstanaScripts()}
179
+ ${localScriptTags}
231
180
  </head>`
232
181
  );
233
182
  }
234
183
  }
235
184
 
185
+ // Include BeeHeard survey based on env var
186
+ function getBeeheardSurveyScripts() {
187
+ const enableBeeheardSurvey = process.env.ENABLE_BEEHEARD_SURVEY;
188
+ return Boolean(enableBeeheardSurvey)
189
+ ? '<script async src="https://beeheard.dal1a.cirrus.ibm.com/survey/preconfig/HHPxpQgN.js" crossorigin></script>'
190
+ : "";
191
+ }
192
+
193
+ // Include Google Analytics based on env var
194
+ function getGAScripts() {
195
+ const gaSiteId = process.env.GA_SITE_ID;
196
+ return Boolean(gaSiteId)
197
+ ? `<script type="text/javascript">
198
+ window.idaPageIsSPA = true;
199
+ window._ibmAnalytics = {
200
+ settings: {
201
+ name: "IBM_Services_Essentials",
202
+ isSpa: true,
203
+ tealiumProfileName: "ibm-web-app",
204
+ },
205
+ trustarc: {
206
+ isCookiePreferencesButtonAlwaysOn: false,
207
+ },
208
+ };
209
+ digitalData = {
210
+ page: {
211
+ pageInfo: {
212
+ ibm: {
213
+ siteID: '${gaSiteId}',
214
+ }
215
+ },
216
+ category: {
217
+ primaryCategory: 'PC100'
218
+ }
219
+ }
220
+ };
221
+ </script>
222
+ <script src="https://1.www.s81c.com/common/stats/ibm-common.js" type="text/javascript" crossorigin></script>`
223
+ : "";
224
+ }
225
+
226
+ // Include Instana monitoring based on env var
227
+ function getInstanaScripts() {
228
+ const instanaReportingUrl = process.env.INSTANA_REPORTING_URL;
229
+ const instanaKey = process.env.INSTANA_KEY;
230
+
231
+ return Boolean(instanaReportingUrl) && Boolean(instanaKey)
232
+ ? `<script type="text/javascript">
233
+ (function(s,t,a,n){s[t]||(s[t]=a,n=s[a]=function(){n.q.push(arguments)},
234
+ n.q=[],n.v=2,n.l=1*new Date)})(window,"InstanaEumObject","ineum");
235
+ ineum('reportingUrl', ${instanaReportingUrl});
236
+ ineum('key', ${instanaKey});
237
+ ineum('trackSessions');
238
+ </script>
239
+ <script defer crossorigin="anonymous" src="https://eum.instana.io/eum.min.js"></script>`
240
+ : "";
241
+ }
242
+
236
243
  module.exports = createBoomerangServer;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@boomerang-io/webapp-spa-server",
3
3
  "description": "Webapp Server for React-based SPA w/ client-side routing",
4
- "version": "1.0.2-beta.0",
4
+ "version": "1.1.0-beta.0",
5
5
  "author": {
6
6
  "name": "Tim Bula",
7
7
  "email": "timrbula@gmail.com"
@@ -31,8 +31,8 @@
31
31
  "compression": "^1.7.4",
32
32
  "cors": "^2.8.5",
33
33
  "dotenv": "^14.2.0",
34
- "express": "^4.17.2",
35
- "helmet": "^5.0.1",
34
+ "express": "^4.17.3",
35
+ "helmet": "^5.0.2",
36
36
  "newrelic": "^8.7.1",
37
37
  "serialize-javascript": "^6.0.0",
38
38
  "yargs": "^17.3.1"