@financial-times/dotcom-middleware-navigation 7.3.0 → 7.3.1
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/dist/node/handleEdition.d.ts +2 -0
- package/dist/node/index.d.ts +1 -0
- package/dist/node/navigation.d.ts +7 -0
- package/dist/node/normalizePath.d.ts +1 -0
- package/dist/tsconfig.tsbuildinfo +2082 -0
- package/package.json +8 -6
- package/src/handleEdition.ts +0 -28
- package/src/index.ts +0 -1
- package/src/navigation.ts +0 -57
- package/src/normalizePath.ts +0 -6
package/package.json
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@financial-times/dotcom-middleware-navigation",
|
|
3
|
-
"version": "7.3.
|
|
3
|
+
"version": "7.3.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/node/index.js",
|
|
6
6
|
"types": "src/index.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
|
-
"tsc": "../../node_modules/.bin/tsc --incremental",
|
|
10
9
|
"clean": "npm run clean:dist && npm run clean:node_modules",
|
|
11
10
|
"clean:dist": "rm -rf dist",
|
|
12
11
|
"clean:node_modules": "rm -rf node_modules",
|
|
12
|
+
"build:node": "tsc",
|
|
13
13
|
"build": "npm run build:node",
|
|
14
|
-
"build:node": "npm run tsc -- --module commonjs --outDir ./dist/node",
|
|
15
14
|
"dev": "npm run build:node -- --watch",
|
|
16
15
|
"preinstall": "[ \"$INIT_CWD\" != \"$PWD\" ] || npm_config_yes=true npx check-engine"
|
|
17
16
|
},
|
|
@@ -19,8 +18,8 @@
|
|
|
19
18
|
"author": "",
|
|
20
19
|
"license": "MIT",
|
|
21
20
|
"dependencies": {
|
|
22
|
-
"@financial-times/dotcom-server-navigation": "
|
|
23
|
-
"@financial-times/dotcom-types-navigation": "
|
|
21
|
+
"@financial-times/dotcom-server-navigation": "file:../../packages/dotcom-server-navigation",
|
|
22
|
+
"@financial-times/dotcom-types-navigation": "file:../dotcom-types-navigation"
|
|
24
23
|
},
|
|
25
24
|
"devDependencies": {
|
|
26
25
|
"check-engine": "^1.10.1",
|
|
@@ -30,6 +29,9 @@
|
|
|
30
29
|
"node": ">= 14.0.0",
|
|
31
30
|
"npm": "7.x || 8.x"
|
|
32
31
|
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist/"
|
|
34
|
+
],
|
|
33
35
|
"repository": {
|
|
34
36
|
"type": "git",
|
|
35
37
|
"repository": "https://github.com/Financial-Times/dotcom-page-kit.git",
|
|
@@ -39,4 +41,4 @@
|
|
|
39
41
|
"volta": {
|
|
40
42
|
"extends": "../../package.json"
|
|
41
43
|
}
|
|
42
|
-
}
|
|
44
|
+
}
|
package/src/handleEdition.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { isEdition } from '@financial-times/dotcom-server-navigation'
|
|
2
|
-
import { Request, Response } from 'express'
|
|
3
|
-
|
|
4
|
-
const defaultEdition = 'uk'
|
|
5
|
-
|
|
6
|
-
export default (request: Request, response: Response): string => {
|
|
7
|
-
// NOTE: The FT-Edition header is set by the CDN and/or next-router...
|
|
8
|
-
// If an edition is selected with a cookie or query string it will be set to that.
|
|
9
|
-
// Otherwise the router will choose the best setting based on GeoIP.
|
|
10
|
-
// <https://github.com/Financial-Times/ft.com-cdn/blob/HEAD/src/vcl/next-editions.vcl>
|
|
11
|
-
// <https://github.com/Financial-Times/next-router/blob/HEAD/server/middleware/editions.js>
|
|
12
|
-
let currentEdition = request.get('FT-Edition') || defaultEdition
|
|
13
|
-
|
|
14
|
-
if (typeof request.query.edition === 'string' && isEdition(request.query.edition)) {
|
|
15
|
-
currentEdition = request.query.edition
|
|
16
|
-
|
|
17
|
-
response.cookie('next-edition', currentEdition, {
|
|
18
|
-
domain: 'ft.com',
|
|
19
|
-
maxAge: 1000 * 60 * 60 * 24 * 365 // 1 year
|
|
20
|
-
})
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// NOTE: n-express overrides res.set() and res.vary() in order to merge all vary headers together.
|
|
24
|
-
// <https://github.com/Financial-Times/n-express/blob/HEAD/src/middleware/vary.js>
|
|
25
|
-
response.vary('FT-Edition')
|
|
26
|
-
|
|
27
|
-
return currentEdition
|
|
28
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './navigation'
|
package/src/navigation.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { Request, Response, NextFunction } from 'express'
|
|
2
|
-
import { TNavigationData } from '@financial-times/dotcom-types-navigation'
|
|
3
|
-
import { Navigation, TNavOptions } from '@financial-times/dotcom-server-navigation'
|
|
4
|
-
import handleEdition from './handleEdition'
|
|
5
|
-
import normalizePath from './normalizePath'
|
|
6
|
-
|
|
7
|
-
type MiddlewareOptions = TNavOptions & {
|
|
8
|
-
enableSubNavigation?: boolean
|
|
9
|
-
getCurrentPath?: Function
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const defaultOptions: MiddlewareOptions = {
|
|
13
|
-
enableSubNavigation: false,
|
|
14
|
-
getCurrentPath: (request) => normalizePath(request.get('ft-vanity-url') || request.path)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const init = (userOptions: MiddlewareOptions = {}) => {
|
|
18
|
-
const options = { ...defaultOptions, ...userOptions }
|
|
19
|
-
const navigation = new Navigation(options)
|
|
20
|
-
|
|
21
|
-
// Not all pages appear in the navigation so this request will fail often.
|
|
22
|
-
// Because it's not critical, ignore the error and move on.
|
|
23
|
-
const getSubNavigationFor = (currentPath) => navigation.getSubNavigationFor(currentPath).catch(() => {})
|
|
24
|
-
|
|
25
|
-
return async (request: Request, response: Response, next: NextFunction) => {
|
|
26
|
-
try {
|
|
27
|
-
// The vanity URL will usually be referenced in the navigation data
|
|
28
|
-
// rather than the underlying path, so prefer that when available.
|
|
29
|
-
// <https://github.com/Financial-Times/ft.com-cdn/blob/4841fbf100e1c561a2f6729b9921ec12bb6b837c/src/vcl/next-preflight.vcl#L213-L219>
|
|
30
|
-
// NOTE: Next router sets the vanity header inc. any query string so it must be normalized.
|
|
31
|
-
const currentPath = options.getCurrentPath(request)
|
|
32
|
-
const currentEdition = handleEdition(request, response)
|
|
33
|
-
|
|
34
|
-
const [menusData, subNavigationData] = await Promise.all([
|
|
35
|
-
navigation.getMenusFor(currentPath, currentEdition),
|
|
36
|
-
options.enableSubNavigation ? getSubNavigationFor(currentPath) : null
|
|
37
|
-
])
|
|
38
|
-
|
|
39
|
-
const editions = navigation.getEditionsFor(currentEdition)
|
|
40
|
-
const subscribeAction = navigation.getSubscribeAction()
|
|
41
|
-
|
|
42
|
-
const navigationData: TNavigationData = {
|
|
43
|
-
editions,
|
|
44
|
-
subscribeAction,
|
|
45
|
-
currentPath,
|
|
46
|
-
...menusData,
|
|
47
|
-
...subNavigationData
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
response.locals.navigation = navigationData
|
|
51
|
-
|
|
52
|
-
next()
|
|
53
|
-
} catch (error) {
|
|
54
|
-
next(error)
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|