Migrate middleware directory to src (#45701)
This commit is contained in:
@@ -193,7 +193,6 @@ jobs:
|
||||
rsync -rptovR ./user-code/assets/./**/*.png ./assets
|
||||
rsync -rptovR ./user-code/data/./**/*.{yml,md} ./data
|
||||
rsync -rptovR ./user-code/components/./**/*.{scss,ts,tsx} ./components
|
||||
rsync -rptovR --ignore-missing-args ./user-code/middleware/./**/*.{js,ts} ./middleware
|
||||
rsync -rptovR ./user-code/src/./**/*.tsx ./src
|
||||
|
||||
- uses: ./.github/actions/warmup-remotejson-cache
|
||||
|
||||
@@ -89,7 +89,6 @@ COPY --chown=node:node assets ./assets
|
||||
COPY --chown=node:node content ./content
|
||||
COPY --chown=node:node src ./src
|
||||
COPY --chown=node:node .remotejson-cache* ./.remotejson-cache
|
||||
COPY --chown=node:node middleware ./middleware
|
||||
COPY --chown=node:node data ./data
|
||||
COPY --chown=node:node next.config.js ./
|
||||
COPY --chown=node:node server.js ./server.js
|
||||
|
||||
@@ -11,7 +11,7 @@ versions:
|
||||
|
||||
The {% data variables.product.prodname_docs %} site was originally a Ruby on Rails web application. Some time later it was converted into a static site powered by [Jekyll](https://jekyllrb.com/). A few years after that it was migrated to [Nanoc](https://nanoc.app/), another Ruby static site generator.
|
||||
|
||||
Today it's a dynamic Node.js webserver powered by Express, using [middleware](https://github.com/github/docs/blob/main/middleware/README.md) to support proper HTTP redirects, language header detection, and dynamic content generation to support the various flavors of {% data variables.product.company_short %}'s product documentation, like {% data variables.product.prodname_dotcom_the_website %} and {% data variables.product.prodname_ghe_server %}.
|
||||
Today it's a dynamic Node.js webserver powered by Express, using middleware to support proper HTTP redirects, language header detection, and dynamic content generation to support the various flavors of {% data variables.product.company_short %}'s product documentation, like {% data variables.product.prodname_dotcom_the_website %} and {% data variables.product.prodname_ghe_server %}.
|
||||
|
||||
The tooling for this site has changed over the years, but many of the tried-and-true authoring conventions of the original Jekyll site have been preserved.
|
||||
|
||||
@@ -94,5 +94,4 @@ For more information about using a codespace for working on {% data variables.pr
|
||||
- [AUTOTITLE](/contributing/writing-for-github-docs/creating-reusable-content)
|
||||
- [Components](https://github.com/github/docs/blob/main/components/README.md)
|
||||
- [Data](https://github.com/github/docs/blob/main/data/README.md)
|
||||
- [Middleware](https://github.com/github/docs/blob/main/middleware/README.md)
|
||||
- [Tests](https://github.com/github/docs/blob/main/tests/README.md)
|
||||
|
||||
@@ -50,7 +50,7 @@ The supported language codes are defined in [lib/languages.js](#src/languages/li
|
||||
|
||||
This site was originally a Ruby on Rails web application. Some time later it was converted into a static site powered by [Jekyll](https://jekyllrb.com/). A few years after that it was migrated to [Nanoc](https://nanoc.app/), another Ruby static site generator.
|
||||
|
||||
Today it's a dynamic Node.js webserver powered by Express, using [middleware](../middleware/README.md) to support proper HTTP redirects, language header detection, and dynamic content generation to support the various flavors of GitHub's product documentation, like GitHub.com and GitHub Enterprise Server.
|
||||
Today it's a dynamic Node.js webserver powered by Express, using middleware to support proper HTTP redirects, language header detection, and dynamic content generation to support the various flavors of GitHub's product documentation, like GitHub.com and GitHub Enterprise Server.
|
||||
|
||||
The tooling for this site has changed over the years, but many of the tried-and-true authoring conventions of the original Jekyll site have been preserved:
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
Pages that use the `product-landing` layout may optionally include an `Examples` section. Currently, we support three types of examples:
|
||||
|
||||
1. Community examples
|
||||
See https://docs.github.com/en/discussions#community-examples.
|
||||
See https://docs.github.com/en/discussions#community-examples. <!-- markdownlint-disable-line search-replace -->
|
||||
|
||||
2. User examples
|
||||
See https://docs.github.com/en/sponsors#community-examples.
|
||||
1. User examples
|
||||
See https://docs.github.com/en/sponsors#community-examples. <!-- markdownlint-disable-line search-replace -->
|
||||
|
||||
## How it works
|
||||
|
||||
@@ -16,9 +16,11 @@ Example data for each product is defined in `data/product-landing-examples`, in
|
||||
|
||||
At the moment, versioning is only supported in code examples. If an example block should be available in **all** versions, you don't need to do anything special. But if an example block should only be available in some versions, you can add a `versions` prop like this:
|
||||
|
||||
```
|
||||
``` yaml
|
||||
- title: Dependabot version update PR
|
||||
description: Example pull request generated by the Dependabot version updates configuration in the Super linter repository.
|
||||
description: >-
|
||||
Example pull request generated by the Dependabot version
|
||||
updates configuration in the Super linter repository.
|
||||
href: /github/super-linter/pull/1398
|
||||
languages:
|
||||
tags:
|
||||
@@ -29,11 +31,11 @@ At the moment, versioning is only supported in code examples. If an example bloc
|
||||
fpt: '*'
|
||||
```
|
||||
|
||||
where the syntax for `versions` is the same as the [frontmatter `versions` property](content/README.md) and can support semver notation.
|
||||
where the syntax for `versions` is the same as the [frontmatter `versions` property](/content/README.md) and can support semver notation.
|
||||
|
||||
## Rendering
|
||||
|
||||
The product example data is added to the `context` object in `middleware/contextualizers/product-examples.js`.
|
||||
The product example data is added to the `context` object in `src/frame/middleware/context/product-examples.js`.
|
||||
|
||||
The data is then rendered by `components/landing`.
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Release notes for GitHub Enterprise Server
|
||||
|
||||
Rendered here: https://docs.github.com/en/enterprise-server@latest/admin/release-notes
|
||||
Rendered here: https://docs.github.com/en/enterprise-server@latest/admin/release-notes <!-- markdownlint-disable-line search-replace -->
|
||||
|
||||
## Adding release notes to a deprecated GitHub Enterprise Server release
|
||||
|
||||
@@ -9,7 +9,7 @@ During the deprecation of a GitHub Enterprise Server release per [this issue tem
|
||||
If a stakeholder requests an update to deprecated release notes, you can update the notes by completing the following steps.
|
||||
|
||||
1. Check out the long-running branch <code>enterprise-<em>VERSION</em>-release</code> and create a PR to update the release notes for the deprecated version on that branch.
|
||||
2. Reach out to #docs-engineering to request a re-scrape and update of the content stored in Azure. See the section about re-scraping content in the [deprecation checklist](/src/ghes-releases/lib/deprecation-steps.md).
|
||||
1. Reach out to #docs-engineering to request a re-scrape and update of the content stored in Azure. See the section about re-scraping content in the [deprecation checklist](/src/ghes-releases/lib/deprecation-steps.md).
|
||||
|
||||
## How it works
|
||||
|
||||
@@ -31,7 +31,7 @@ Note that patch files can be deprecated individually (i.e., hidden on the docs s
|
||||
|
||||
### Middleware processing
|
||||
|
||||
The YAML data is processed and sorted by `middleware/contextualizers/ghes-release-notes.js` and added to the `context` object.
|
||||
The YAML data is processed and sorted by `src/release-notes/middleware/context/ghes-release-notes.js` and added to the `context` object.
|
||||
|
||||
### Layouts
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Release notes for GitHub AE
|
||||
|
||||
Rendered here: https://docs.github.com/en/github-ae@latest/admin/release-notes
|
||||
Rendered here: https://docs.github.com/en/github-ae@latest/admin/release-notes <!-- markdownlint-disable-line search-replace -->
|
||||
|
||||
## How it works
|
||||
|
||||
@@ -20,7 +20,7 @@ Note that patch files can be deprecated individually (i.e., hidden on the docs s
|
||||
|
||||
### Middleware processing
|
||||
|
||||
The YAML data is processed and sorted by `middleware/contextualizers/ghae-release-notes.js` and added to the `context` object.
|
||||
The YAML data is processed and sorted by `src/release-notes/middleware/ghae-release-notes.js` and added to the `context` object.
|
||||
|
||||
### Layouts
|
||||
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
# Middleware
|
||||
|
||||
Each file in this directory exports an Express Middleware function.
|
||||
|
||||
For more info, see https://expressjs.com/en/guide/using-middleware.html
|
||||
|
||||
## Subdirectories
|
||||
|
||||
There are subdirectories for different types of middleware:
|
||||
|
||||
- [contextualizers](contextualizers) modify the `req.context` object that is used to render pages.
|
||||
- [redirects](redirects) handle... redirects!
|
||||
@@ -7,8 +7,8 @@ import isArchivedVersion from '#src/archives/lib/is-archived-version.js'
|
||||
import {
|
||||
setFastlySurrogateKey,
|
||||
SURROGATE_ENUMS,
|
||||
} from '../../../middleware/set-fastly-surrogate-key.js'
|
||||
import { archivedCacheControl } from '../../../middleware/cache-control.js'
|
||||
} from '#src/frame/middleware/set-fastly-surrogate-key.js'
|
||||
import { archivedCacheControl } from '#src/frame/middleware/cache-control.js'
|
||||
|
||||
// This module handles requests for the CSS and JS assets for
|
||||
// deprecated GitHub Enterprise versions by routing them to static content in
|
||||
|
||||
@@ -13,13 +13,13 @@ import isArchivedVersion from '#src/archives/lib/is-archived-version.js'
|
||||
import {
|
||||
setFastlySurrogateKey,
|
||||
SURROGATE_ENUMS,
|
||||
} from '../../../middleware/set-fastly-surrogate-key.js'
|
||||
} from '#src/frame/middleware/set-fastly-surrogate-key.js'
|
||||
import got from 'got'
|
||||
import { readCompressedJsonFileFallbackLazily } from '#src/frame/lib/read-json-file.js'
|
||||
import { archivedCacheControl, languageCacheControl } from '../../../middleware/cache-control.js'
|
||||
import { archivedCacheControl, languageCacheControl } from '#src/frame/middleware/cache-control.js'
|
||||
import { pathLanguagePrefixed, languagePrefixPathRegex } from '#src/languages/lib/languages.js'
|
||||
import getRedirect, { splitPathByLanguage } from '#src/redirects/lib/get-redirect.js'
|
||||
import getRemoteJSON from '../../../middleware/get-remote-json.js'
|
||||
import getRemoteJSON from '#src/frame/lib/get-remote-json.js'
|
||||
|
||||
const REMOTE_ENTERPRISE_STORAGE_URL = 'https://githubdocs.azureedge.net/enterprise'
|
||||
|
||||
@@ -67,7 +67,7 @@ const cacheAggressively = (res) => {
|
||||
// 3. ~4000ms
|
||||
//
|
||||
// ...if the limit we set is 3.
|
||||
// Our own timeout, in ./middleware/timeout.js defaults to 10 seconds.
|
||||
// Our own timeout, in #src/frame/middleware/timeout.js defaults to 10 seconds.
|
||||
// So there's no point in trying more attempts than 3 because it would
|
||||
// just timeout on the 10s. (i.e. 1000 + 2000 + 4000 + 8000 > 10,000)
|
||||
const retryConfiguration = { limit: 3 }
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
import { program } from 'commander'
|
||||
import semver from 'semver'
|
||||
|
||||
import getRemoteJSON from '../../../middleware/get-remote-json.js'
|
||||
import getRemoteJSON from '#src/frame/lib/get-remote-json.js'
|
||||
import {
|
||||
deprecated,
|
||||
firstReleaseStoredInBlobStorage,
|
||||
|
||||
@@ -2,7 +2,7 @@ import { describe, jest, test } from '@jest/globals'
|
||||
|
||||
import enterpriseServerReleases from '#src/versions/lib/enterprise-server-releases.js'
|
||||
import { get, getDOM } from '../../../tests/helpers/e2etest.js'
|
||||
import { SURROGATE_ENUMS } from '../../../middleware/set-fastly-surrogate-key.js'
|
||||
import { SURROGATE_ENUMS } from '#src/frame/middleware/set-fastly-surrogate-key.js'
|
||||
|
||||
jest.useFakeTimers({ legacyFakeTimers: true })
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@ import fs from 'fs/promises'
|
||||
|
||||
import sharp from 'sharp'
|
||||
|
||||
import { assetCacheControl, defaultCacheControl } from '../../../middleware/cache-control.js'
|
||||
import { assetCacheControl, defaultCacheControl } from '#src/frame/middleware/cache-control.js'
|
||||
import {
|
||||
setFastlySurrogateKey,
|
||||
SURROGATE_ENUMS,
|
||||
} from '../../../middleware/set-fastly-surrogate-key.js'
|
||||
} from '#src/frame/middleware/set-fastly-surrogate-key.js'
|
||||
|
||||
/**
|
||||
* This is the indicator that is a virtual part of the URL.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
setFastlySurrogateKey,
|
||||
SURROGATE_ENUMS,
|
||||
} from '../../../middleware/set-fastly-surrogate-key.js'
|
||||
} from '#src/frame/middleware/set-fastly-surrogate-key.js'
|
||||
|
||||
export default function setStaticAssetCaching(req, res, next) {
|
||||
if (isChecksummed(req.path)) {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { jest } from '@jest/globals'
|
||||
import sharp from 'sharp'
|
||||
import { fileTypeFromBuffer } from 'file-type'
|
||||
|
||||
import { SURROGATE_ENUMS } from '../../../middleware/set-fastly-surrogate-key.js'
|
||||
import { SURROGATE_ENUMS } from '#src/frame/middleware/set-fastly-surrogate-key.js'
|
||||
import { get, head } from '../../../tests/helpers/e2etest.js'
|
||||
|
||||
describe('dynamic assets', () => {
|
||||
|
||||
@@ -2,7 +2,7 @@ import nock from 'nock'
|
||||
import { expect, jest } from '@jest/globals'
|
||||
|
||||
import { checkCachingHeaders } from '../../../tests/helpers/caching-headers.js'
|
||||
import { setDefaultFastlySurrogateKey } from '../../../middleware/set-fastly-surrogate-key.js'
|
||||
import { setDefaultFastlySurrogateKey } from '#src/frame/middleware/set-fastly-surrogate-key.js'
|
||||
import archivedEnterpriseVersionsAssets from '#src/archives/middleware/archived-enterprise-versions-assets.js'
|
||||
|
||||
function mockRequest(path, { headers }) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import { decode } from 'html-entities'
|
||||
import matter from '#src/frame/lib/read-frontmatter.js'
|
||||
import { renderContent } from '#src/content-render/index.js'
|
||||
import getApplicableVersions from '#src/versions/lib/get-applicable-versions.js'
|
||||
import contextualize from '../../../middleware/context.js'
|
||||
import contextualize from '#src/frame/middleware/context/context.js'
|
||||
import shortVersions from '#src/versions/middleware/short-versions.js'
|
||||
import { ROOT } from '#src/frame/lib/constants.js'
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { program } from 'commander'
|
||||
import fpt from '#src/versions/lib/non-enterprise-default-version.js'
|
||||
import { allVersionKeys } from '#src/versions/lib/all-versions.js'
|
||||
import { liquid } from '#src/content-render/index.js'
|
||||
import contextualize from '../../middleware/context.js'
|
||||
import contextualize from '#src/frame/middleware/context/context.js'
|
||||
|
||||
const layoutFilename = path.posix.join(process.cwd(), 'src/dev-toc/layout.html')
|
||||
const layout = fs.readFileSync(layoutFilename, 'utf8')
|
||||
|
||||
@@ -4,7 +4,7 @@ import Ajv from 'ajv'
|
||||
import addFormats from 'ajv-formats'
|
||||
import { schemas, hydroNames } from './lib/schema.js'
|
||||
import catchMiddlewareError from '#src/observability/middleware/catch-middleware-error.js'
|
||||
import { noCacheControl } from '../../middleware/cache-control.js'
|
||||
import { noCacheControl } from '#src/frame/middleware/cache-control.js'
|
||||
import { formatErrors } from './lib/middleware-errors.js'
|
||||
import { publish as _publish } from './lib/hydro.js'
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import express from 'express'
|
||||
import middleware from '../../../middleware/index.js'
|
||||
import middleware from '#src/frame/middleware/index.js'
|
||||
|
||||
function createApp() {
|
||||
const app = express()
|
||||
|
||||
5
src/frame/middleware/README.md
Normal file
5
src/frame/middleware/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# Middleware
|
||||
|
||||
Each file in this directory exports an Express Middleware function.
|
||||
|
||||
For more info, see https://expressjs.com/en/guide/using-middleware.html
|
||||
@@ -19,14 +19,14 @@ import handleErrors from '#src/observability/middleware/handle-errors.js'
|
||||
import handleNextDataPath from './handle-next-data-path.js'
|
||||
import detectLanguage from '#src/languages/middleware/detect-language.js'
|
||||
import reloadTree from './reload-tree.js'
|
||||
import context from './context.js'
|
||||
import context from './context/context.js'
|
||||
import shortVersions from '#src/versions/middleware/short-versions.js'
|
||||
import languageCodeRedirects from '#src/redirects/middleware/language-code-redirects.js'
|
||||
import handleRedirects from '#src/redirects/middleware/handle-redirects.js'
|
||||
import findPage from './find-page.js'
|
||||
import blockRobots from './block-robots.js'
|
||||
import archivedEnterpriseVersionsAssets from '#src/archives/middleware/archived-enterprise-versions-assets.js'
|
||||
import api from './api/index.js'
|
||||
import api from './api.js'
|
||||
import healthz from './healthz.js'
|
||||
import productIcons from './product-icons.js'
|
||||
import manifestJson from './manifest-json.js'
|
||||
@@ -40,15 +40,15 @@ import triggerError from '#src/observability/middleware/trigger-error.js'
|
||||
import secretScanning from '#src/secret-scanning/middleware/secret-scanning.js'
|
||||
import ghesReleaseNotes from '#src/release-notes/middleware/ghes-release-notes.js'
|
||||
import ghaeReleaseNotes from '#src/release-notes/middleware/ghae-release-notes.js'
|
||||
import whatsNewChangelog from './contextualizers/whats-new-changelog.js'
|
||||
import layout from './contextualizers/layout.js'
|
||||
import currentProductTree from './contextualizers/current-product-tree.js'
|
||||
import genericToc from './contextualizers/generic-toc.js'
|
||||
import breadcrumbs from './contextualizers/breadcrumbs.js'
|
||||
import glossaries from './contextualizers/glossaries.js'
|
||||
import whatsNewChangelog from './context/whats-new-changelog.js'
|
||||
import layout from './context/layout.js'
|
||||
import currentProductTree from './context/current-product-tree.js'
|
||||
import genericToc from './context/generic-toc.js'
|
||||
import breadcrumbs from './context/breadcrumbs.js'
|
||||
import glossaries from './context/glossaries.js'
|
||||
import features from '#src/versions/middleware/features.js'
|
||||
import productExamples from './contextualizers/product-examples.js'
|
||||
import productGroups from './contextualizers/product-groups.js'
|
||||
import productExamples from './context/product-examples.js'
|
||||
import productGroups from './context/product-groups.js'
|
||||
import featuredLinks from '#src/landings/middleware/featured-links.js'
|
||||
import learningTrack from '#src/learning-track/middleware/learning-track.js'
|
||||
import next from './next.js'
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { languageKeys } from '#src/languages/lib/languages.js'
|
||||
|
||||
import { makeLanguageSurrogateKey } from '../../../middleware/set-fastly-surrogate-key.js'
|
||||
import { makeLanguageSurrogateKey } from '#src/frame/middleware/set-fastly-surrogate-key.js'
|
||||
import purgeEdgeCache from '#src/workflows/purge-edge-cache.js'
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { languageKeys } from '#src/languages/lib/languages.js'
|
||||
import { blockIndex } from '../../../middleware/block-robots.js'
|
||||
import { blockIndex } from '#src/frame/middleware/block-robots.js'
|
||||
import { get, getDOMCached as getDOM } from '../../../tests/helpers/e2etest.js'
|
||||
import Page from '#src/frame/lib/page.js'
|
||||
import { jest } from '@jest/globals'
|
||||
|
||||
@@ -47,7 +47,7 @@ main(program.opts(), program.args)
|
||||
// 3. ~4000ms
|
||||
//
|
||||
// ...if the limit we set is 3.
|
||||
// Our own timeout, in ./middleware/timeout.js defaults to 10 seconds.
|
||||
// Our own timeout, in #src/frame/middleware/timeout.js defaults to 10 seconds.
|
||||
// So there's no point in trying more attempts than 3 because it would
|
||||
// just timeout on the 10s. (i.e. 1000 + 2000 + 4000 + 8000 > 10,000)
|
||||
const retryConfiguration = {
|
||||
|
||||
@@ -10,7 +10,7 @@ import { Low } from 'lowdb'
|
||||
import { JSONFile } from 'lowdb/node'
|
||||
|
||||
import shortVersions from '#src/versions/middleware/short-versions.js'
|
||||
import contextualize from '../../../middleware/context.js'
|
||||
import contextualize from '#src/frame/middleware/context/context.js'
|
||||
import features from '#src/versions/middleware/features.js'
|
||||
import getRedirect from '#src/redirects/lib/get-redirect.js'
|
||||
import warmServer from '#src/frame/lib/warm-server.js'
|
||||
@@ -943,7 +943,7 @@ async function innerFetch(core, url, config = {}) {
|
||||
// 3. ~4000ms
|
||||
//
|
||||
// ...if the limit we set is 3.
|
||||
// Our own timeout, in ./middleware/timeout.js defaults to 10 seconds.
|
||||
// Our own timeout, in #src/frame/middleware/timeout.js defaults to 10 seconds.
|
||||
// So there's no point in trying more attempts than 3 because it would
|
||||
// just timeout on the 10s. (i.e. 1000 + 2000 + 4000 + 8000 > 10,000)
|
||||
const retry = {
|
||||
|
||||
@@ -2,7 +2,7 @@ import path from 'path'
|
||||
import statsd from './statsd.js'
|
||||
|
||||
export default function instrumentMiddleware(middleware, relativePath) {
|
||||
// Requires the file as if it were being required from '../middleware/index.js'.
|
||||
// Requires the file as if it were being required from '#src/frame/middleware/index.js'.
|
||||
// This is a little wonky, but let's us write `app.use(instrument(path))` and
|
||||
// maintain the name of the file, instead of hard-coding it for each middleware.
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import FailBot from '../lib/failbot.js'
|
||||
import { nextApp } from '../../../middleware/next.js'
|
||||
import { nextApp } from '#src/frame/middleware/next.js'
|
||||
import {
|
||||
setFastlySurrogateKey,
|
||||
SURROGATE_ENUMS,
|
||||
} from '../../../middleware/set-fastly-surrogate-key.js'
|
||||
import { errorCacheControl } from '../../../middleware/cache-control.js'
|
||||
} from '#src/frame/middleware/set-fastly-surrogate-key.js'
|
||||
import { errorCacheControl } from '#src/frame/middleware/cache-control.js'
|
||||
|
||||
const DEBUG_MIDDLEWARE_TESTS = Boolean(JSON.parse(process.env.DEBUG_MIDDLEWARE_TESTS || 'false'))
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import express from 'express'
|
||||
|
||||
import statsd from '#src/observability/lib/statsd.js'
|
||||
import { defaultCacheControl } from '../../middleware/cache-control.js'
|
||||
import { defaultCacheControl } from '#src/frame/middleware/cache-control.js'
|
||||
import catchMiddlewareError from '#src/observability/middleware/catch-middleware-error.js'
|
||||
import {
|
||||
SURROGATE_ENUMS,
|
||||
setFastlySurrogateKey,
|
||||
makeLanguageSurrogateKey,
|
||||
} from '../../middleware/set-fastly-surrogate-key.js'
|
||||
} from '#src/frame/middleware/set-fastly-surrogate-key.js'
|
||||
import shortVersions from '#src/versions/middleware/short-versions.js'
|
||||
import contextualize from '../../middleware/context.js'
|
||||
import contextualize from '#src/frame/middleware/context/context.js'
|
||||
import features from '#src/versions/middleware/features.js'
|
||||
import getRedirect from '#src/redirects/lib/get-redirect.js'
|
||||
import { isArchivedVersionByPath } from '#src/archives/lib/is-archived-version.js'
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { beforeAll } from '@jest/globals'
|
||||
|
||||
import { get } from '../../../tests/helpers/e2etest.js'
|
||||
import { SURROGATE_ENUMS } from '../../../middleware/set-fastly-surrogate-key.js'
|
||||
import { SURROGATE_ENUMS } from '#src/frame/middleware/set-fastly-surrogate-key.js'
|
||||
import { latest } from '#src/versions/lib/enterprise-server-releases.js'
|
||||
|
||||
const makeURL = (pathname) => `/api/pageinfo/v1?${new URLSearchParams({ pathname })}`
|
||||
|
||||
@@ -22,7 +22,7 @@ The results comprise the `page.redirects` object, whose keys are always only the
|
||||
Sometimes it contains the specific plan/version (e.g. `/enterprise-server@3.0/v3/integrations` to `enterprise-server@3.0/developers/apps`) and sometimes it's just the plain path
|
||||
(e.g. `/articles/viewing-your-repositorys-workflows` to `/actions/monitoring-and-troubleshooting-workflows`)
|
||||
|
||||
All of the above are merged into a global redirects object. This object gets added to `req.context` via `middleware/context.js` and is made accessible on every request.
|
||||
All of the above are merged into a global redirects object. This object gets added to `req.context` via `src/frame/middleware/context/context.js` and is made accessible on every request.
|
||||
|
||||
In the `handle-redirects.js` middleware, the language part of the URL is
|
||||
removed, looked up, and if matched to something, redirects with language
|
||||
@@ -40,7 +40,7 @@ if (newPath) {
|
||||
|
||||
Archived Enterprise redirects account for a much smaller percentage of redirects on the docs site.
|
||||
|
||||
Some background on archival: a snapshot of the HTML files for each deprecated Enterprise Server version is archived in a separate repo and proxied to docs.github.com via `middleware/archived-enterprise-versions.js`.
|
||||
Some background on archival: a snapshot of the HTML files for each deprecated Enterprise Server version is archived in a separate repo and proxied to docs.github.com via `src/archives/middleware/archived-enterprise-versions.js`.
|
||||
|
||||
Starting with Enterprise Server 2.18, we updated the archival process to start preserving frontmatter and permalink redirects. But these redirects for 2.13 to 2.17 are not recoverable.
|
||||
|
||||
@@ -62,7 +62,7 @@ As a workaround for these lost redirects, we have two files in `lib/redirects/st
|
||||
version range of 2.13 to 2.17. So every key in `archived-frontmatter-valid-urls.json`
|
||||
corresponds to a file that would work.
|
||||
|
||||
Here's how the `middleware/archived-enterprise-versions.js` fallback works: if someone tries to access an article that was updated via a now-lost frontmatter redirect (for example, an article at the path `/en/enterprise/2.15/user/articles/viewing-contributions-on-your-profile-page`), the middleware will first look for a redirect in `archived-redirects-from-213-to-217.json`. If it does not find one, it will look for it in `archived-frontmatter-valid-urls.json` that contains the requested path. If it finds it, it will redirect to it to because that file knows exactly which URLs are valid in
|
||||
Here's how the `src/archives/middleware/archived-enterprise-versions.js` fallback works: if someone tries to access an article that was updated via a now-lost frontmatter redirect (for example, an article at the path `/en/enterprise/2.15/user/articles/viewing-contributions-on-your-profile-page`), the middleware will first look for a redirect in `archived-redirects-from-213-to-217.json`. If it does not find one, it will look for it in `archived-frontmatter-valid-urls.json` that contains the requested path. If it finds it, it will redirect to it to because that file knows exactly which URLs are valid in
|
||||
`help-docs-archived-enterprise-versions`.
|
||||
|
||||
## Tests
|
||||
|
||||
@@ -3,7 +3,7 @@ import { URL } from 'url'
|
||||
import { pathLanguagePrefixed } from '#src/languages/lib/languages.js'
|
||||
import { deprecatedWithFunctionalRedirects } from '#src/versions/lib/enterprise-server-releases.js'
|
||||
import getRedirect from '../lib/get-redirect.js'
|
||||
import { defaultCacheControl, languageCacheControl } from '../../../middleware/cache-control.js'
|
||||
import { defaultCacheControl, languageCacheControl } from '#src/frame/middleware/cache-control.js'
|
||||
|
||||
export default function handleRedirects(req, res, next) {
|
||||
// never redirect assets
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import languages from '#src/languages/lib/languages.js'
|
||||
import { defaultCacheControl } from '../../../middleware/cache-control.js'
|
||||
import { defaultCacheControl } from '#src/frame/middleware/cache-control.js'
|
||||
|
||||
const redirectPatterns = Object.values(languages)
|
||||
.map((language) => language.redirectPatterns || [])
|
||||
|
||||
@@ -2,7 +2,7 @@ import express from 'express'
|
||||
import path from 'path'
|
||||
|
||||
import { readCompressedJsonFileFallbackLazily } from '#src/frame/lib/read-json-file.js'
|
||||
import { defaultCacheControl } from '../../../middleware/cache-control.js'
|
||||
import { defaultCacheControl } from '#src/frame/middleware/cache-control.js'
|
||||
import { REST_DATA_DIR } from '../lib/index.js'
|
||||
|
||||
const clientSideRestAPIRedirects = readCompressedJsonFileFallbackLazily(
|
||||
|
||||
@@ -6,7 +6,7 @@ import { get } from '../../../tests/helpers/e2etest.js'
|
||||
import {
|
||||
SURROGATE_ENUMS,
|
||||
makeLanguageSurrogateKey,
|
||||
} from '../../../middleware/set-fastly-surrogate-key.js'
|
||||
} from '#src/frame/middleware/set-fastly-surrogate-key.js'
|
||||
|
||||
describe('anchor-redirect api', () => {
|
||||
const clientSideRedirects = JSON.parse(
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import express from 'express'
|
||||
|
||||
import FailBot from '#src/observability/lib/failbot.js'
|
||||
import { searchCacheControl } from '../../../middleware/cache-control.js'
|
||||
import { searchCacheControl } from '#src/frame/middleware/cache-control.js'
|
||||
import catchMiddlewareError from '#src/observability/middleware/catch-middleware-error.js'
|
||||
import {
|
||||
setFastlySurrogateKey,
|
||||
SURROGATE_ENUMS,
|
||||
} from '../../../middleware/set-fastly-surrogate-key.js'
|
||||
} from '#src/frame/middleware/set-fastly-surrogate-key.js'
|
||||
import { getSearchResults } from './es-search.js'
|
||||
import { getSearchFromRequest } from './get-search-request.js'
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import { jest, test, expect } from '@jest/globals'
|
||||
|
||||
import { describeIfElasticsearchURL } from '../../../tests/helpers/conditional-runs.js'
|
||||
import { get, getDOM } from '../../../tests/helpers/e2etest.js'
|
||||
import { SURROGATE_ENUMS } from '../../../middleware/set-fastly-surrogate-key.js'
|
||||
import { SURROGATE_ENUMS } from '#src/frame/middleware/set-fastly-surrogate-key.js'
|
||||
|
||||
if (!process.env.ELASTICSEARCH_URL) {
|
||||
console.warn(
|
||||
|
||||
@@ -19,7 +19,7 @@ work loads:
|
||||
|
||||
## How it works
|
||||
|
||||
At its root, the `src/shielding/middleware/index.js` is injected into our
|
||||
At its root, the `src/shielding/frame/middleware/index.js` is injected into our
|
||||
Express server. From there, it loads all its individual middleware handlers.
|
||||
|
||||
Each middleware is one file that focuses on a single use-case. The
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import statsd from '#src/observability/lib/statsd.js'
|
||||
import { defaultCacheControl } from '../../../middleware/cache-control.js'
|
||||
import { defaultCacheControl } from '#src/frame/middleware/cache-control.js'
|
||||
|
||||
const STATSD_KEY = 'middleware.handle_invalid_nextjs_paths'
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { defaultCacheControl } from '../../../middleware/cache-control.js'
|
||||
import { defaultCacheControl } from '#src/frame/middleware/cache-control.js'
|
||||
|
||||
// When a *whole* path is considerered junk.
|
||||
const JUNK_PATHS = new Set([
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import statsd from '#src/observability/lib/statsd.js'
|
||||
import { allTools } from '#src/tools/lib/all-tools.js'
|
||||
import { allPlatforms } from '#src/tools/lib/all-platforms.js'
|
||||
import { defaultCacheControl } from '../../../middleware/cache-control.js'
|
||||
import { defaultCacheControl } from '#src/frame/middleware/cache-control.js'
|
||||
|
||||
const STATSD_KEY = 'middleware.handle_invalid_querystring_values'
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import statsd from '#src/observability/lib/statsd.js'
|
||||
import { noCacheControl, defaultCacheControl } from '../../../middleware/cache-control.js'
|
||||
import { noCacheControl, defaultCacheControl } from '#src/frame/middleware/cache-control.js'
|
||||
|
||||
const STATSD_KEY = 'middleware.handle_invalid_querystrings'
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
import fs from 'fs'
|
||||
|
||||
import { errorCacheControl } from '../../../middleware/cache-control.js'
|
||||
import { errorCacheControl } from '#src/frame/middleware/cache-control.js'
|
||||
|
||||
export default function handleOldNextDataPaths(req, res, next) {
|
||||
if (req.path.startsWith('/_next/data/') && !req.path.startsWith('/_next/data/development/')) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import rateLimit from 'express-rate-limit'
|
||||
|
||||
import statsd from '#src/observability/lib/statsd.js'
|
||||
import { noCacheControl } from '../../../middleware/cache-control.js'
|
||||
import { noCacheControl } from '#src/frame/middleware/cache-control.js'
|
||||
|
||||
const EXPIRES_IN_AS_SECONDS = 60
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { SURROGATE_ENUMS } from '../../../middleware/set-fastly-surrogate-key.js'
|
||||
// import { setFastlySurrogateKey } from '../../../middleware/set-fastly-surrogate-key.js'
|
||||
import { SURROGATE_ENUMS } from '#src/frame/middleware/set-fastly-surrogate-key.js'
|
||||
// import { setFastlySurrogateKey } from '#src/frame/middleware/set-fastly-surrogate-key.js'
|
||||
import { get } from '../../../tests/helpers/e2etest.js'
|
||||
|
||||
describe('honeypotting', () => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import express from 'express'
|
||||
import { getWebhook } from '../lib/index.js'
|
||||
import { allVersions } from '#src/versions/lib/all-versions.js'
|
||||
import { defaultCacheControl } from '../../../middleware/cache-control.js'
|
||||
import { defaultCacheControl } from '#src/frame/middleware/cache-control.js'
|
||||
|
||||
const router = express.Router()
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { get } from '../../../tests/helpers/e2etest.js'
|
||||
import {
|
||||
SURROGATE_ENUMS,
|
||||
makeLanguageSurrogateKey,
|
||||
} from '../../../middleware/set-fastly-surrogate-key.js'
|
||||
} from '#src/frame/middleware/set-fastly-surrogate-key.js'
|
||||
import { describe, expect } from '@jest/globals'
|
||||
|
||||
describe('webhooks v1 middleware', () => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
import { SURROGATE_ENUMS } from '../../middleware/set-fastly-surrogate-key.js'
|
||||
import { SURROGATE_ENUMS } from '#src/frame/middleware/set-fastly-surrogate-key.js'
|
||||
import purgeEdgeCache from './purge-edge-cache.js'
|
||||
|
||||
// This will purge every response that *contains*
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { SURROGATE_ENUMS } from '../../middleware/set-fastly-surrogate-key.js'
|
||||
import { SURROGATE_ENUMS } from '#src/frame/middleware/set-fastly-surrogate-key.js'
|
||||
|
||||
export function checkCachingHeaders(res, defaultSurrogateKey = false, minMaxAge = 60 * 60) {
|
||||
expect(res.headers['set-cookie']).toBeUndefined()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { blockIndex } from '../../middleware/block-robots.js'
|
||||
import { blockIndex } from '#src/frame/middleware/block-robots.js'
|
||||
import { productMap } from '#src/products/lib/all-products.js'
|
||||
import enterpriseServerReleases from '#src/versions/lib/enterprise-server-releases.js'
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { expect, jest } from '@jest/globals'
|
||||
|
||||
import { SURROGATE_ENUMS } from '../../middleware/set-fastly-surrogate-key.js'
|
||||
import { SURROGATE_ENUMS } from '#src/frame/middleware/set-fastly-surrogate-key.js'
|
||||
import { get } from '../helpers/e2etest.js'
|
||||
|
||||
describe('favicon assets', () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import sharp from 'sharp'
|
||||
|
||||
import { SURROGATE_ENUMS } from '../../middleware/set-fastly-surrogate-key.js'
|
||||
import { SURROGATE_ENUMS } from '#src/frame/middleware/set-fastly-surrogate-key.js'
|
||||
import { get, getDOM } from '../helpers/e2etest.js'
|
||||
|
||||
describe('manifest', () => {
|
||||
|
||||
@@ -4,7 +4,7 @@ import robotsParser from 'robots-parser'
|
||||
import {
|
||||
SURROGATE_ENUMS,
|
||||
makeLanguageSurrogateKey,
|
||||
} from '../../middleware/set-fastly-surrogate-key.js'
|
||||
} from '#src/frame/middleware/set-fastly-surrogate-key.js'
|
||||
import { get } from '../helpers/e2etest.js'
|
||||
|
||||
describe('robots.txt', () => {
|
||||
|
||||
@@ -6,7 +6,7 @@ import CspParse from 'csp-parse'
|
||||
import {
|
||||
SURROGATE_ENUMS,
|
||||
makeLanguageSurrogateKey,
|
||||
} from '../../middleware/set-fastly-surrogate-key.js'
|
||||
} from '#src/frame/middleware/set-fastly-surrogate-key.js'
|
||||
import { describe, jest } from '@jest/globals'
|
||||
|
||||
const AZURE_STORAGE_URL = 'githubdocs.azureedge.net'
|
||||
|
||||
@@ -5,7 +5,7 @@ import http from 'http'
|
||||
import { expect, describe, test } from '@jest/globals'
|
||||
|
||||
import Page from '#src/frame/lib/page.js'
|
||||
import findPage from '../../middleware/find-page.js'
|
||||
import findPage from '#src/frame/middleware/find-page.js'
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import os from 'os'
|
||||
import { rimraf } from 'rimraf'
|
||||
import { expect, test, describe, beforeAll, afterAll } from '@jest/globals'
|
||||
import nock from 'nock'
|
||||
import getRemoteJSON, { cache } from '../../middleware/get-remote-json.js'
|
||||
import getRemoteJSON, { cache } from '#src/frame/lib/get-remote-json.js'
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user