@boomerang-io/webapp-spa-server 1.0.2-beta.3 → 1.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.
- package/README.md +11 -4
- package/index.js +70 -65
- 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 |
|
|
66
|
-
| NEW_RELIC_LICENSE_KEY |
|
|
67
|
-
|
|
|
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
|
|
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
|
|
@@ -98,15 +96,13 @@ function createBoomerangServer({
|
|
|
98
96
|
})
|
|
99
97
|
);
|
|
100
98
|
appRouter.get("/*", (req, res) =>
|
|
101
|
-
injectEnvDataAndScriptsIntoHTML(
|
|
99
|
+
injectEnvDataAndScriptsIntoHTML({
|
|
102
100
|
res,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
ENABLE_BEEHEARD_SURVEY
|
|
109
|
-
)
|
|
101
|
+
appRoot: APP_ROOT,
|
|
102
|
+
buildDir: BUILD_DIR,
|
|
103
|
+
injectedDataKeys: HTML_HEAD_INJECTED_DATA_KEYS,
|
|
104
|
+
injectedScripts: HTML_HEAD_INJECTED_SCRIPTS,
|
|
105
|
+
})
|
|
110
106
|
);
|
|
111
107
|
} else {
|
|
112
108
|
appRouter.use("/", express.static(path.join(process.cwd(), BUILD_DIR)));
|
|
@@ -137,58 +133,8 @@ function createBoomerangServer({
|
|
|
137
133
|
* @param {string} buildDir - build directory for building up path to index.html file
|
|
138
134
|
* @param {string} injectedDataKeys - string of comma delimited values
|
|
139
135
|
* @param {string} injectedScripts - string of comma delimited values
|
|
140
|
-
* @param {string} appRoot - root context off app. Used for script injection
|
|
141
|
-
* @param {string} gaSiteId - siteID to be injected on scripts to support GA
|
|
142
|
-
* @param {string} baseLaunchUrl - base url to determine GA primaryCategory
|
|
143
|
-
* @param {boolean} enableBeeheardSurvey - true/false value configured at helm to decide to insert survey script
|
|
144
136
|
*/
|
|
145
|
-
function injectEnvDataAndScriptsIntoHTML(
|
|
146
|
-
res,
|
|
147
|
-
buildDir,
|
|
148
|
-
injectedDataKeys,
|
|
149
|
-
injectedScripts,
|
|
150
|
-
appRoot,
|
|
151
|
-
gaSiteId,
|
|
152
|
-
enableBeeheardSurvey
|
|
153
|
-
) {
|
|
154
|
-
/**
|
|
155
|
-
* Create objects to be injected into application via the HEAD tag
|
|
156
|
-
*/
|
|
157
|
-
// Build script for GA integration
|
|
158
|
-
const headScripstGA = Boolean(gaSiteId)
|
|
159
|
-
? `<script type="text/javascript">
|
|
160
|
-
window.idaPageIsSPA = true;
|
|
161
|
-
window._ibmAnalytics = {
|
|
162
|
-
settings: {
|
|
163
|
-
name: "IBM_Services_Essentials",
|
|
164
|
-
isSpa: true,
|
|
165
|
-
tealiumProfileName: "ibm-web-app",
|
|
166
|
-
},
|
|
167
|
-
trustarc: {
|
|
168
|
-
isCookiePreferencesButtonAlwaysOn: false,
|
|
169
|
-
},
|
|
170
|
-
};
|
|
171
|
-
digitalData = {
|
|
172
|
-
page: {
|
|
173
|
-
pageInfo: {
|
|
174
|
-
ibm: {
|
|
175
|
-
siteID: '${gaSiteId}',
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
category: {
|
|
179
|
-
primaryCategory: 'PC100'
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
</script>
|
|
184
|
-
<script src="https://1.www.s81c.com/common/stats/ibm-common.js" type="text/javascript" crossorigin></script>
|
|
185
|
-
`
|
|
186
|
-
: "";
|
|
187
|
-
|
|
188
|
-
const headScriptBeeheardSurvey = Boolean(enableBeeheardSurvey)
|
|
189
|
-
? '<script async src="https://beeheard.dal1a.cirrus.ibm.com/survey/preconfig/HHPxpQgN.js" crossorigin></script>'
|
|
190
|
-
: "";
|
|
191
|
-
|
|
137
|
+
function injectEnvDataAndScriptsIntoHTML({ res, buildDir, appRoot, injectedDataKeys, injectedScripts }) {
|
|
192
138
|
// Build up object of external data to append
|
|
193
139
|
const headInjectedData = injectedDataKeys.split(",").reduce((acc, key) => {
|
|
194
140
|
acc[key] = process.env[key];
|
|
@@ -196,7 +142,7 @@ function injectEnvDataAndScriptsIntoHTML(
|
|
|
196
142
|
}, {});
|
|
197
143
|
|
|
198
144
|
// Build up string of scripts to append, absolute path
|
|
199
|
-
const
|
|
145
|
+
const localScriptTags = injectedScripts
|
|
200
146
|
? injectedScripts
|
|
201
147
|
.split(",")
|
|
202
148
|
.reduce((acc, currentValue) => `${acc}<script src="${appRoot}/${currentValue}"></script>`, "")
|
|
@@ -227,12 +173,71 @@ function injectEnvDataAndScriptsIntoHTML(
|
|
|
227
173
|
isJSON: true,
|
|
228
174
|
})};
|
|
229
175
|
</script>
|
|
230
|
-
${
|
|
231
|
-
${
|
|
232
|
-
${
|
|
176
|
+
${getBeeheardSurveyScripts()}
|
|
177
|
+
${getGAScripts()}
|
|
178
|
+
${getInstanaScripts()}
|
|
179
|
+
${localScriptTags}
|
|
233
180
|
</head>`
|
|
234
181
|
);
|
|
235
182
|
}
|
|
236
183
|
}
|
|
237
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
|
+
|
|
238
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
|
|
4
|
+
"version": "1.1.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.
|
|
35
|
-
"helmet": "^5.0.
|
|
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"
|