@boomerang-io/webapp-spa-server 1.0.0-beta.0 → 1.0.2-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/cli.js +14 -2
  2. package/index.js +16 -11
  3. package/package.json +2 -2
package/cli.js CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ const boomerangLogger = require("@boomerang-io/logger-middleware")("webapp-spa-server/index.js");
4
+ const logger = boomerangLogger.logger;
3
5
  /**
4
6
  * Import and execute app
5
7
  */
@@ -22,7 +24,6 @@ require("yargs") // eslint-disable-line
22
24
  describe: "CORS configuration using cors package. Accepts JSON string.",
23
25
  type: "string",
24
26
  })
25
-
26
27
  .option("disableInjectHTMLHeadData", {
27
28
  alias: "d",
28
29
  describe: "Enable injection of data and scripts into the head of the HTML file.",
@@ -36,5 +37,16 @@ require("yargs") // eslint-disable-line
36
37
  type: "string",
37
38
  })
38
39
  .coerce({
39
- cors: JSON.parse,
40
+ cors: (arg) => {
41
+ if (arg) {
42
+ return JSON.parse(arg);
43
+ }
44
+ },
45
+ })
46
+ .fail(function (msg, err) {
47
+ logger.error(msg);
48
+ if (err) {
49
+ throw err;
50
+ }
51
+ process.exit(1);
40
52
  }).argv;
package/index.js CHANGED
@@ -36,10 +36,9 @@ function createBoomerangServer({
36
36
  NEW_RELIC_LICENSE_KEY,
37
37
  HTML_HEAD_INJECTED_SCRIPTS,
38
38
  BUILD_DIR = "build",
39
- BASE_LAUNCH_ENV_URL,
40
39
  GA_SITE_ID,
40
+ ENABLE_BEEHEARD_SURVEY,
41
41
  } = process.env;
42
- logger.debug("PROCESS ENV: ", process.env);
43
42
 
44
43
  // Monitoring
45
44
  if (NEW_RELIC_APP_NAME && NEW_RELIC_LICENSE_KEY) {
@@ -61,9 +60,11 @@ function createBoomerangServer({
61
60
 
62
61
  // Security
63
62
  const helmet = require("helmet");
64
- app.use(helmet({
65
- contentSecurityPolicy: false,
66
- }));
63
+ app.use(
64
+ helmet({
65
+ contentSecurityPolicy: false,
66
+ })
67
+ );
67
68
  app.disable("x-powered-by");
68
69
  app.use(cors(corsConfig));
69
70
 
@@ -85,9 +86,7 @@ function createBoomerangServer({
85
86
  * It will be returned on the second route
86
87
  * https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#serving-apps-with-client-side-routing
87
88
  */
88
- logger.debug("0 - disableInjectHTMLHeadData: ", disableInjectHTMLHeadData);
89
89
  if (!disableInjectHTMLHeadData) {
90
- logger.debug("1 - URL and ID: ",GA_SITE_ID,BASE_LAUNCH_ENV_URL);
91
90
  appRouter.use(
92
91
  "/",
93
92
  express.static(path.join(process.cwd(), BUILD_DIR), {
@@ -102,11 +101,11 @@ function createBoomerangServer({
102
101
  HTML_HEAD_INJECTED_SCRIPTS,
103
102
  APP_ROOT,
104
103
  GA_SITE_ID,
105
- BASE_LAUNCH_ENV_URL
104
+ ENABLE_BEEHEARD_SURVEY
106
105
  )
107
106
  );
108
107
  } else {
109
- logger.debug("1 - disableInjectHTMLHeadData: ",disableInjectHTMLHeadData);
108
+ logger.debug("1 - disableInjectHTMLHeadData: ", disableInjectHTMLHeadData);
110
109
  appRouter.use("/", express.static(path.join(process.cwd(), BUILD_DIR)));
111
110
  }
112
111
 
@@ -138,6 +137,7 @@ function createBoomerangServer({
138
137
  * @param {string} appRoot - root context off app. Used for script injection
139
138
  * @param {string} gaSiteId - siteID to be injected on scripts to support GA
140
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
141
  */
142
142
  function injectEnvDataAndScriptsIntoHTML(
143
143
  res,
@@ -146,13 +146,12 @@ function injectEnvDataAndScriptsIntoHTML(
146
146
  injectedScripts,
147
147
  appRoot,
148
148
  gaSiteId,
149
- baseLaunchUrl
149
+ enableBeeheardSurvey
150
150
  ) {
151
151
  /**
152
152
  * Create objects to be injected into application via the HEAD tag
153
153
  */
154
154
  // Build script for GA integration
155
- logger.debug("2 - GA Site ID: ",gaSiteId);
156
155
  const headScripstGA = Boolean(gaSiteId)
157
156
  ? `<script type="text/javascript">
158
157
  window.idaPageIsSPA = true;
@@ -182,6 +181,11 @@ function injectEnvDataAndScriptsIntoHTML(
182
181
  <script src="//1.www.s81c.com/common/stats/ibm-common.js" type="text/javascript"></script>
183
182
  `
184
183
  : "";
184
+
185
+ const headScriptBeeheardSurvey = Boolean(enableBeeheardSurvey)
186
+ ? '<script async src="https://beeheard.dal1a.cirrus.ibm.com/survey/preconfig/HHPxpQgN.js"></script>'
187
+ : "";
188
+
185
189
  // Build up object of external data to append
186
190
  const headInjectedData = injectedDataKeys.split(",").reduce((acc, key) => {
187
191
  acc[key] = process.env[key];
@@ -222,6 +226,7 @@ function injectEnvDataAndScriptsIntoHTML(
222
226
  })};
223
227
  </script>
224
228
  ${headScripstGA}
229
+ ${headScriptBeeheardSurvey}
225
230
  ${headScriptsTags}
226
231
  </head>`
227
232
  );
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.0-beta.0",
4
+ "version": "1.0.2-beta.0",
5
5
  "author": {
6
6
  "name": "Tim Bula",
7
7
  "email": "timrbula@gmail.com"
@@ -25,7 +25,7 @@
25
25
  "start": "node tester.js"
26
26
  },
27
27
  "dependencies": {
28
- "@boomerang-io/logger-middleware": "^0.0.2",
28
+ "@boomerang-io/logger-middleware": "1.0.0",
29
29
  "@cloudnative/health-connect": "^2.1.0",
30
30
  "body-parser": "^1.19.1",
31
31
  "compression": "^1.7.4",