Block a few more things in AIRGAP (#17657)
* Block a few more things in AIRGAP * Update middleware/context.js Co-authored-by: Vanessa Yuen <6842965+vanessayuenn@users.noreply.github.com> * Update product-landing.html Co-authored-by: Vanessa Yuen <6842965+vanessayuenn@users.noreply.github.com>
This commit is contained in:
@@ -42,7 +42,7 @@ COPY --chown=node:node --from=install /usr/src/docs/dist /usr/src/docs/dist
|
|||||||
ENV NODE_ENV production
|
ENV NODE_ENV production
|
||||||
|
|
||||||
# Use Lunr instead of Algolia
|
# Use Lunr instead of Algolia
|
||||||
ENV USE_LUNR true
|
ENV AIRGAP true
|
||||||
|
|
||||||
# Copy only what's needed to run the server
|
# Copy only what's needed to run the server
|
||||||
COPY --chown=node:node assets ./assets
|
COPY --chown=node:node assets ./assets
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
{% include breadcrumbs %}
|
{% include breadcrumbs %}
|
||||||
|
|
||||||
<div class="graphql-container">
|
<div class="graphql-container">
|
||||||
|
{% if process.env.AIRGAP %}
|
||||||
|
<p>GraphQL explorer is not available on this environment.</p>
|
||||||
|
{% else %}
|
||||||
<iframe id="graphiql" class="graphql-explorer" scrolling="no" src="{{ graphql.explorerUrl }}" allowfullscreen>
|
<iframe id="graphiql" class="graphql-explorer" scrolling="no" src="{{ graphql.explorerUrl }}" allowfullscreen>
|
||||||
<p>You must have iframes enabled to use this feature.</p>
|
<p>You must have iframes enabled to use this feature.</p>
|
||||||
</iframe>
|
</iframe>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
<script id="search-options" type="application/json">{{ searchOptions }}</script>
|
<script id="expose" type="application/json">{{ expose }}</script>
|
||||||
<script src="{{ builtAssets.main.js }}"></script>
|
<script src="{{ builtAssets.main.js }}"></script>
|
||||||
|
|||||||
14
javascripts/airgap-links.js
Normal file
14
javascripts/airgap-links.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
export default function airgapLinks () {
|
||||||
|
// When in an airgapped environment,
|
||||||
|
// show a tooltip on external links
|
||||||
|
const { airgap } = JSON.parse(document.getElementById('expose').text)
|
||||||
|
if (!airgap) return
|
||||||
|
|
||||||
|
const externaLinks = Array.from(
|
||||||
|
document.querySelectorAll('a[href^="http"], a[href^="//"]')
|
||||||
|
)
|
||||||
|
externaLinks.forEach(link => {
|
||||||
|
link.classList.add('tooltipped')
|
||||||
|
link.setAttribute('aria-label', 'This link may not work in this environment.')
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -18,6 +18,7 @@ import allArticles from './all-articles'
|
|||||||
import devToc from './dev-toc'
|
import devToc from './dev-toc'
|
||||||
import releaseNotes from './release-notes'
|
import releaseNotes from './release-notes'
|
||||||
import showMore from './show-more'
|
import showMore from './show-more'
|
||||||
|
import airgapLinks from './airgap-links'
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', async () => {
|
document.addEventListener('DOMContentLoaded', async () => {
|
||||||
displayPlatformSpecificContent()
|
displayPlatformSpecificContent()
|
||||||
@@ -34,6 +35,7 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||||||
allArticles()
|
allArticles()
|
||||||
devToc()
|
devToc()
|
||||||
showMore()
|
showMore()
|
||||||
|
airgapLinks()
|
||||||
releaseNotes()
|
releaseNotes()
|
||||||
initializeEvents()
|
initializeEvents()
|
||||||
experiment()
|
experiment()
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export default function search () {
|
|||||||
languages,
|
languages,
|
||||||
versions,
|
versions,
|
||||||
nonEnterpriseDefaultVersion
|
nonEnterpriseDefaultVersion
|
||||||
} = JSON.parse(document.getElementById('search-options').text)
|
} = JSON.parse(document.getElementById('expose').text).searchOptions
|
||||||
version = deriveVersionFromPath(versions, nonEnterpriseDefaultVersion)
|
version = deriveVersionFromPath(versions, nonEnterpriseDefaultVersion)
|
||||||
language = deriveLanguageCodeFromPath(languages)
|
language = deriveLanguageCodeFromPath(languages)
|
||||||
|
|
||||||
|
|||||||
@@ -20,9 +20,13 @@
|
|||||||
|
|
||||||
<div class="mt-2">
|
<div class="mt-2">
|
||||||
<div>
|
<div>
|
||||||
|
{% if process.env.AIRGAP %}
|
||||||
|
<p>GraphQL explorer is not available on this environment.</p>
|
||||||
|
{% else %}
|
||||||
<iframe id="graphiql" class="graphql-explorer" scrolling="no" src="{{ graphql.explorerUrl }}">
|
<iframe id="graphiql" class="graphql-explorer" scrolling="no" src="{{ graphql.explorerUrl }}">
|
||||||
<p>You must have iframes enabled to use this feature.</p>
|
<p>You must have iframes enabled to use this feature.</p>
|
||||||
</iframe>
|
</iframe>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
|
|||||||
@@ -41,6 +41,7 @@
|
|||||||
{% if page.product_video %}
|
{% if page.product_video %}
|
||||||
<div class="col-12 col-lg-6">
|
<div class="col-12 col-lg-6">
|
||||||
<div class="position-relative" style="padding-bottom:56.25%;">
|
<div class="position-relative" style="padding-bottom:56.25%;">
|
||||||
|
{% unless process.env.AIRGAP %}
|
||||||
<iframe
|
<iframe
|
||||||
title="{{ page.shortTitle }} Video"
|
title="{{ page.shortTitle }} Video"
|
||||||
class="top-0 left-0 position-absolute box-shadow-large rounded-1 width-full height-full"
|
class="top-0 left-0 position-absolute box-shadow-large rounded-1 width-full height-full"
|
||||||
@@ -48,6 +49,7 @@
|
|||||||
frameborder="0"
|
frameborder="0"
|
||||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen
|
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen
|
||||||
></iframe>
|
></iframe>
|
||||||
|
{% endunless %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ module.exports = async function syncSearchIndexes (opts = {}) {
|
|||||||
|
|
||||||
// The page version will be the new version, e.g., free-pro-team@latest, enterprise-server@2.22
|
// The page version will be the new version, e.g., free-pro-team@latest, enterprise-server@2.22
|
||||||
const records = await buildRecords(indexName, indexablePages, pageVersion, languageCode)
|
const records = await buildRecords(indexName, indexablePages, pageVersion, languageCode)
|
||||||
const index = process.env.USE_LUNR
|
const index = process.env.AIRGAP
|
||||||
? new LunrIndex(indexName, records)
|
? new LunrIndex(indexName, records)
|
||||||
: new AlgoliaIndex(indexName, records)
|
: new AlgoliaIndex(indexName, records)
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ module.exports = async function syncSearchIndexes (opts = {}) {
|
|||||||
fs.writeFileSync(cacheFile, JSON.stringify(index, null, 2))
|
fs.writeFileSync(cacheFile, JSON.stringify(index, null, 2))
|
||||||
console.log('wrote dry-run index to disk: ', cacheFile)
|
console.log('wrote dry-run index to disk: ', cacheFile)
|
||||||
} else {
|
} else {
|
||||||
if (process.env.USE_LUNR) {
|
if (process.env.AIRGAP) {
|
||||||
await index.write()
|
await index.write()
|
||||||
console.log('wrote index to file: ', indexName)
|
console.log('wrote index to file: ', indexName)
|
||||||
} else {
|
} else {
|
||||||
@@ -93,7 +93,7 @@ module.exports = async function syncSearchIndexes (opts = {}) {
|
|||||||
|
|
||||||
// Fetch a list of index names and cache it for tests
|
// Fetch a list of index names and cache it for tests
|
||||||
// to ensure that an index exists for every language and GHE version
|
// to ensure that an index exists for every language and GHE version
|
||||||
const remoteIndexNames = process.env.USE_LUNR
|
const remoteIndexNames = process.env.AIRGAP
|
||||||
? await getLunrIndexNames()
|
? await getLunrIndexNames()
|
||||||
: await getRemoteIndexNames()
|
: await getRemoteIndexNames()
|
||||||
const cachedIndexNamesFile = path.join(__dirname, './cached-index-names.json')
|
const cachedIndexNamesFile = path.join(__dirname, './cached-index-names.json')
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ module.exports = async function contextualize (req, res, next) {
|
|||||||
featureFlags.forEach(featureFlagName => {
|
featureFlags.forEach(featureFlagName => {
|
||||||
req.context.process.env[featureFlagName] = process.env[featureFlagName]
|
req.context.process.env[featureFlagName] = process.env[featureFlagName]
|
||||||
})
|
})
|
||||||
|
if (process.env.AIRGAP) req.context.process.env.AIRGAP = true
|
||||||
|
|
||||||
// define each context property explicitly for code-search friendliness
|
// define each context property explicitly for code-search friendliness
|
||||||
// e.g. searches for "req.context.page" will include results from this file
|
// e.g. searches for "req.context.page" will include results from this file
|
||||||
@@ -48,11 +49,16 @@ module.exports = async function contextualize (req, res, next) {
|
|||||||
// JS + CSS asset paths
|
// JS + CSS asset paths
|
||||||
req.context.builtAssets = builtAssets
|
req.context.builtAssets = builtAssets
|
||||||
|
|
||||||
|
// Object exposing selected variables to client
|
||||||
|
req.context.expose = JSON.stringify({
|
||||||
// Languages and versions for search
|
// Languages and versions for search
|
||||||
req.context.searchOptions = JSON.stringify({
|
searchOptions: {
|
||||||
languages: Object.keys(languages),
|
languages: Object.keys(languages),
|
||||||
versions: searchVersions,
|
versions: searchVersions,
|
||||||
nonEnterpriseDefaultVersion
|
nonEnterpriseDefaultVersion
|
||||||
|
},
|
||||||
|
// `|| undefined` won't show at all for production
|
||||||
|
airgap: Boolean(process.env.AIRGAP) || undefined
|
||||||
})
|
})
|
||||||
|
|
||||||
return next()
|
return next()
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ router.get('/', async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const results = process.env.USE_LUNR
|
const results = process.env.AIRGAP
|
||||||
? await loadLunrResults({ version, language, query, limit })
|
? await loadLunrResults({ version, language, query, limit })
|
||||||
: await loadAlgoliaResults({ version, language, query, limit })
|
: await loadAlgoliaResults({ version, language, query, limit })
|
||||||
return res.status(200).json(results)
|
return res.status(200).json(results)
|
||||||
|
|||||||
Reference in New Issue
Block a user