FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
github-docs/middleware/context.js at main · 0xdevalias/github-docs · GitHub
0xdevalias
/
github-docs
Public
forked from
github/docs
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
github-docs
/
middleware
/
context.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
59 lines (52 loc) · 2.64 KB
Breadcrumbs
github-docs
/
middleware
/
context.js
Copy path
File metadata and controls
59 lines (52 loc) · 2.64 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const
languages
=
require
(
'../lib/languages'
)
const
enterpriseServerReleases
=
require
(
'../lib/enterprise-server-releases'
)
const
allVersions
=
require
(
'../lib/all-versions'
)
const
allProducts
=
require
(
'../lib/all-products'
)
const
activeProducts
=
Object
.
values
(
allProducts
)
.
filter
(
product
=>
!
product
.
wip
&&
!
product
.
hidden
)
const
{
getVersionStringFromPath
,
getProductStringFromPath
,
getPathWithoutLanguage
}
=
require
(
'../lib/path-utils'
)
const
productNames
=
require
(
'../lib/product-names'
)
const
warmServer
=
require
(
'../lib/warm-server'
)
const
featureFlags
=
Object
.
keys
(
require
(
'../feature-flags'
)
)
const
builtAssets
=
require
(
'../lib/built-asset-urls'
)
const
searchVersions
=
require
(
'../lib/search/versions'
)
const
nonEnterpriseDefaultVersion
=
require
(
'../lib/non-enterprise-default-version'
)
// Supply all route handlers with a baseline `req.context` object
// Note that additional middleware in middleware/index.js adds to this context object
module
.
exports
=
async
function
contextualize
(
req
,
res
,
next
)
{
// Ensure that we load some data only once on first request
const
{
site
,
redirects
,
siteTree
,
pages
:
pageMap
}
=
await
warmServer
(
)
req
.
context
=
{
}
// make feature flag environment variables accessible in layouts
req
.
context
.
process
=
{
env
:
{
}
}
featureFlags
.
forEach
(
featureFlagName
=>
{
req
.
context
.
process
.
env
[
featureFlagName
]
=
process
.
env
[
featureFlagName
]
}
)
// define each context property explicitly for code-search friendliness
// e.g. searches for "req.context.page" will include results from this file
req
.
context
.
currentLanguage
=
req
.
language
req
.
context
.
currentVersion
=
getVersionStringFromPath
(
req
.
path
)
req
.
context
.
currentProduct
=
getProductStringFromPath
(
req
.
path
)
req
.
context
.
allProducts
=
allProducts
req
.
context
.
activeProducts
=
activeProducts
req
.
context
.
allVersions
=
allVersions
req
.
context
.
currentPathWithoutLanguage
=
getPathWithoutLanguage
(
req
.
path
)
req
.
context
.
currentPath
=
req
.
path
req
.
context
.
query
=
req
.
query
req
.
context
.
languages
=
languages
req
.
context
.
productNames
=
productNames
req
.
context
.
enterpriseServerReleases
=
enterpriseServerReleases
req
.
context
.
enterpriseServerVersions
=
Object
.
keys
(
allVersions
)
.
filter
(
version
=>
version
.
startsWith
(
'enterprise-server@'
)
)
req
.
context
.
redirects
=
redirects
req
.
context
.
site
=
site
[
req
.
language
]
.
site
req
.
context
.
siteTree
=
siteTree
req
.
context
.
pages
=
pageMap
// JS + CSS asset paths
req
.
context
.
builtAssets
=
builtAssets
// Languages and versions for search
req
.
context
.
searchOptions
=
JSON
.
stringify
(
{
languages
:
Object
.
keys
(
languages
)
,
versions
:
searchVersions
,
nonEnterpriseDefaultVersion
}
)
return
next
(
)
}
Back
|
FazBrowse Home
|
New Git URL