@quintype/framework 7.33.1-amp-chart-beat-changes.0 → 7.33.1-qtraceid.2
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 +3 -2
- package/server/routes.js +17 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quintype/framework",
|
|
3
|
-
"version": "7.33.1-
|
|
3
|
+
"version": "7.33.1-qtraceid.2",
|
|
4
4
|
"description": "Libraries to help build Quintype Node.js apps",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"engines": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"homepage": "https://github.com/quintype/quintype-node-framework#readme",
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@ampproject/toolbox-optimizer": "2.8.3",
|
|
34
|
-
"@quintype/amp": "^2.20.
|
|
34
|
+
"@quintype/amp": "^2.20.0",
|
|
35
35
|
"@quintype/backend": "^2.7.0",
|
|
36
36
|
"@quintype/components": "^3.5.0",
|
|
37
37
|
"@quintype/prerender-node": "^3.2.26",
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
"redux": "^4.1.1",
|
|
60
60
|
"request-promise": "^4.2.6",
|
|
61
61
|
"sleep-promise": "^9.1.0",
|
|
62
|
+
"uuid": "^11.0.5",
|
|
62
63
|
"winston": "3.3.3"
|
|
63
64
|
},
|
|
64
65
|
"devDependencies": {
|
package/server/routes.js
CHANGED
|
@@ -29,6 +29,7 @@ const bodyParser = require('body-parser')
|
|
|
29
29
|
const get = require('lodash/get')
|
|
30
30
|
const { URL } = require('url')
|
|
31
31
|
const prerender = require('@quintype/prerender-node')
|
|
32
|
+
const { v4: uuidv4 } = require('uuid');
|
|
32
33
|
|
|
33
34
|
/**
|
|
34
35
|
* *upstreamQuintypeRoutes* connects various routes directly to the upstream API server.
|
|
@@ -43,7 +44,7 @@ const prerender = require('@quintype/prerender-node')
|
|
|
43
44
|
* @param {boolean} opts.forwardFavicon Forward favicon requests to the CMS (default false)
|
|
44
45
|
* @param {boolean} opts.isSitemapUrlEnabled To enable /news_sitemap/today and /news_sitemap/yesterday sitemap news url (default /news_sitemap.xml)
|
|
45
46
|
*/
|
|
46
|
-
exports.upstreamQuintypeRoutes = function upstreamQuintypeRoutes
|
|
47
|
+
exports.upstreamQuintypeRoutes = function upstreamQuintypeRoutes(
|
|
47
48
|
app,
|
|
48
49
|
{
|
|
49
50
|
forwardAmp = false,
|
|
@@ -64,7 +65,9 @@ exports.upstreamQuintypeRoutes = function upstreamQuintypeRoutes (
|
|
|
64
65
|
})
|
|
65
66
|
|
|
66
67
|
apiProxy.on('proxyReq', (proxyReq, req, res, options) => {
|
|
68
|
+
const qtTraceId = (req && req.headers && req.headers['qt-trace-id']) || uuidv4();
|
|
67
69
|
proxyReq.setHeader('Host', getClient(req.hostname).getHostname())
|
|
70
|
+
proxyReq.setHeader('qt-trace-id', qtTraceId)
|
|
68
71
|
})
|
|
69
72
|
|
|
70
73
|
const _sMaxAge = get(config, ['publisher', 'upstreamRoutesSmaxage'], sMaxAge)
|
|
@@ -146,12 +149,12 @@ exports.upstreamQuintypeRoutes = function upstreamQuintypeRoutes (
|
|
|
146
149
|
}
|
|
147
150
|
|
|
148
151
|
// istanbul ignore next
|
|
149
|
-
function renderServiceWorkerFn
|
|
152
|
+
function renderServiceWorkerFn(res, layout, params, callback) {
|
|
150
153
|
return res.render(layout, params, callback)
|
|
151
154
|
}
|
|
152
155
|
|
|
153
156
|
// istanbul ignore next
|
|
154
|
-
function toFunction
|
|
157
|
+
function toFunction(value, toRequire) {
|
|
155
158
|
if (value === true) {
|
|
156
159
|
value = require(toRequire)
|
|
157
160
|
}
|
|
@@ -162,20 +165,20 @@ function toFunction (value, toRequire) {
|
|
|
162
165
|
return () => value
|
|
163
166
|
}
|
|
164
167
|
|
|
165
|
-
function getDomainSlug
|
|
168
|
+
function getDomainSlug(publisherConfig, hostName) {
|
|
166
169
|
if (!publisherConfig.domain_mapping) {
|
|
167
170
|
return undefined
|
|
168
171
|
}
|
|
169
172
|
return publisherConfig.domain_mapping[hostName] || null
|
|
170
173
|
}
|
|
171
174
|
|
|
172
|
-
function withConfigPartial
|
|
175
|
+
function withConfigPartial(
|
|
173
176
|
getClient,
|
|
174
177
|
logError,
|
|
175
178
|
publisherConfig = require('./publisher-config'),
|
|
176
179
|
configWrapper = config => config
|
|
177
180
|
) {
|
|
178
|
-
return function withConfig
|
|
181
|
+
return function withConfig(f, staticParams) {
|
|
179
182
|
return function (req, res, next) {
|
|
180
183
|
const domainSlug = getDomainSlug(publisherConfig, req.hostname)
|
|
181
184
|
const client = getClient(req.hostname)
|
|
@@ -199,7 +202,7 @@ function withConfigPartial (
|
|
|
199
202
|
}
|
|
200
203
|
}
|
|
201
204
|
|
|
202
|
-
exports.withError = function withError
|
|
205
|
+
exports.withError = function withError(handler, logError) {
|
|
203
206
|
return async (req, res, next, opts) => {
|
|
204
207
|
try {
|
|
205
208
|
await handler(req, res, next, opts)
|
|
@@ -211,15 +214,15 @@ exports.withError = function withError (handler, logError) {
|
|
|
211
214
|
}
|
|
212
215
|
}
|
|
213
216
|
|
|
214
|
-
function convertToDomain
|
|
217
|
+
function convertToDomain(path) {
|
|
215
218
|
if (!path) {
|
|
216
219
|
return path
|
|
217
220
|
}
|
|
218
221
|
return new URL(path).origin
|
|
219
222
|
}
|
|
220
223
|
|
|
221
|
-
function wrapLoadDataWithMultiDomain
|
|
222
|
-
return async function loadDataWrapped
|
|
224
|
+
function wrapLoadDataWithMultiDomain(publisherConfig, f, configPos) {
|
|
225
|
+
return async function loadDataWrapped() {
|
|
223
226
|
const { domainSlug } = arguments[arguments.length - 1]
|
|
224
227
|
const config = arguments[configPos]
|
|
225
228
|
const primaryHostUrl = convertToDomain(config['sketches-host'])
|
|
@@ -257,7 +260,7 @@ function wrapLoadDataWithMultiDomain (publisherConfig, f, configPos) {
|
|
|
257
260
|
* @param {module:routes~Handler} handler The Handler to run
|
|
258
261
|
* @param {Object} opts Options that will be passed to the handler. These options will be merged with a *config* and *client*
|
|
259
262
|
*/
|
|
260
|
-
function getWithConfig
|
|
263
|
+
function getWithConfig(app, route, handler, opts = {}) {
|
|
261
264
|
const configWrapper = opts.configWrapper
|
|
262
265
|
const {
|
|
263
266
|
getClient = require('./api-client').getClient,
|
|
@@ -309,7 +312,7 @@ function getWithConfig (app, route, handler, opts = {}) {
|
|
|
309
312
|
* @param {boolean|function} enableExternalStories If set to true, then for every request an external story api call is made and renders the story-page if the story is found. (default: false)
|
|
310
313
|
* @param {string|function} externalIdPattern This string specifies the external id pattern the in the url. Mention `EXTERNAL_ID` to specify the position of external id in the url. Ex: "/parent-section/child-section/EXTERNAL_ID"
|
|
311
314
|
*/
|
|
312
|
-
exports.isomorphicRoutes = function isomorphicRoutes
|
|
315
|
+
exports.isomorphicRoutes = function isomorphicRoutes(
|
|
313
316
|
app,
|
|
314
317
|
{
|
|
315
318
|
generateRoutes,
|
|
@@ -629,7 +632,7 @@ exports.proxyGetRequest = function (app, route, handler, opts = {}) {
|
|
|
629
632
|
|
|
630
633
|
getWithConfig(app, route, proxyHandler, opts)
|
|
631
634
|
|
|
632
|
-
async function proxyHandler
|
|
635
|
+
async function proxyHandler(req, res, next, { config, client }) {
|
|
633
636
|
try {
|
|
634
637
|
const result = await handler(req.params, { config, client })
|
|
635
638
|
if (typeof result === 'string' && result.startsWith('http')) {
|
|
@@ -642,7 +645,7 @@ exports.proxyGetRequest = function (app, route, handler, opts = {}) {
|
|
|
642
645
|
sendResult(null)
|
|
643
646
|
}
|
|
644
647
|
|
|
645
|
-
function sendResult
|
|
648
|
+
function sendResult(result) {
|
|
646
649
|
if (result) {
|
|
647
650
|
res.setHeader('Cache-Control', cacheControl)
|
|
648
651
|
res.setHeader('Vary', 'Accept-Encoding')
|