From 7586a1a9521d3aa29b134713c32f434dff799a51 Mon Sep 17 00:00:00 2001 From: Kevin Heis Date: Mon, 6 Nov 2023 12:05:48 -0800 Subject: [PATCH] Migrate middleware directory to src (#45701) --- .../workflows/azure-preview-env-deploy.yml | 1 - Dockerfile | 1 - .../creating-a-local-environment.md | 3 +-- contributing/development.md | 2 +- data/product-examples/README.md | 16 ++++++++------- .../release-notes/enterprise-server/README.md | 6 +++--- data/release-notes/github-ae/README.md | 4 ++-- middleware/README.md | 12 ----------- .../archived-enterprise-versions-assets.js | 4 ++-- .../archived-enterprise-versions.js | 8 ++++---- src/archives/scripts/warmup-remotejson.js | 2 +- .../tests/deprecated-enterprise-versions.js | 2 +- src/assets/middleware/dynamic-assets.js | 4 ++-- src/assets/middleware/static-asset-caching.js | 2 +- src/assets/tests/dynamic-assets.js | 2 +- src/assets/tests/static-assets-1.js | 2 +- src/content-linter/tests/category-pages.js | 2 +- src/dev-toc/generate.js | 2 +- src/events/middleware.js | 2 +- src/frame/lib/app.js | 2 +- .../frame/lib}/get-remote-json.js | 0 src/frame/middleware/README.md | 5 +++++ {middleware => src/frame/middleware}/abort.js | 0 .../index.js => src/frame/middleware/api.js | 0 .../frame/middleware}/block-robots.js | 0 .../frame/middleware}/build-info.js | 0 .../frame/middleware}/cache-control.js | 0 .../middleware}/categories-for-support.js | 0 .../frame/middleware/context}/breadcrumbs.js | 0 .../frame/middleware/context}/context.js | 0 .../context}/current-product-tree.js | 0 .../frame/middleware/context}/generic-toc.js | 0 .../frame/middleware/context}/glossaries.js | 0 .../frame/middleware/context}/layout.js | 0 .../middleware/context}/product-examples.js | 0 .../middleware/context}/product-groups.js | 0 .../context}/whats-new-changelog.js | 0 .../frame/middleware}/cookie-parser.js | 0 .../frame/middleware}/fast-head.js | 0 .../frame/middleware}/fastly-behavior.js | 0 .../frame/middleware}/fastly-cache-test.js | 0 .../frame/middleware}/favicons.js | 0 .../frame/middleware}/find-page.js | 0 .../middleware}/halt-on-dropped-connection.js | 0 .../middleware}/handle-next-data-path.js | 0 .../frame/middleware}/healthz.js | 0 .../frame/middleware}/helmet.js | 0 {middleware => src/frame/middleware}/index.js | 20 +++++++++---------- .../frame/middleware}/manifest-json.js | 0 .../frame/middleware}/mock-va-portal.js | 0 {middleware => src/frame/middleware}/next.js | 0 .../frame/middleware}/product-icons.js | 0 .../frame/middleware}/reload-tree.js | 0 .../frame/middleware}/remote-ip.js | 0 .../frame/middleware}/render-page.js | 0 .../frame/middleware}/robots.js | 0 .../middleware}/set-fastly-surrogate-key.js | 0 .../frame/middleware}/timeout.js | 0 .../frame/middleware}/trailing-slashes.js | 0 .../purge-fastly-edge-cache-per-language.js | 2 +- src/languages/tests/frame.js | 2 +- .../scripts/check-github-github-links.js | 2 +- .../scripts/rendered-content-link-checker.js | 4 ++-- .../lib/instrument-middleware.js | 2 +- src/observability/middleware/handle-errors.js | 6 +++--- src/pageinfo/middleware.js | 6 +++--- src/pageinfo/tests/pageinfo.js | 2 +- src/redirects/README.md | 6 +++--- src/redirects/middleware/handle-redirects.js | 2 +- .../middleware/language-code-redirects.js | 2 +- src/rest/api/anchor-redirect.js | 2 +- src/rest/tests/api.js | 2 +- src/search/middleware/search.js | 4 ++-- src/search/tests/rendering.js | 2 +- src/shielding/README.md | 2 +- .../middleware/handle-invalid-nextjs-paths.js | 2 +- .../middleware/handle-invalid-paths.js | 2 +- .../handle-invalid-query-string-values.js | 2 +- .../handle-invalid-query-strings.js | 2 +- .../middleware/handle-old-next-data-paths.js | 2 +- src/shielding/middleware/rate-limit.js | 2 +- src/shielding/tests/shielding.js | 4 ++-- src/webhooks/middleware/webhooks.js | 2 +- src/webhooks/tests/api.js | 2 +- src/workflows/purge-fastly-edge-cache.js | 2 +- tests/helpers/caching-headers.js | 2 +- tests/rendering/block-robots.js | 2 +- tests/rendering/favicons.js | 2 +- tests/rendering/manifest.js | 2 +- tests/rendering/robots-txt.js | 2 +- tests/rendering/server.js | 2 +- tests/unit/find-page-middleware.js | 2 +- tests/unit/get-remote-json.js | 2 +- 93 files changed, 91 insertions(+), 99 deletions(-) delete mode 100644 middleware/README.md rename {middleware => src/frame/lib}/get-remote-json.js (100%) create mode 100644 src/frame/middleware/README.md rename {middleware => src/frame/middleware}/abort.js (100%) rename middleware/api/index.js => src/frame/middleware/api.js (100%) rename {middleware => src/frame/middleware}/block-robots.js (100%) rename {middleware => src/frame/middleware}/build-info.js (100%) rename {middleware => src/frame/middleware}/cache-control.js (100%) rename {middleware => src/frame/middleware}/categories-for-support.js (100%) rename {middleware/contextualizers => src/frame/middleware/context}/breadcrumbs.js (100%) rename {middleware => src/frame/middleware/context}/context.js (100%) rename {middleware/contextualizers => src/frame/middleware/context}/current-product-tree.js (100%) rename {middleware/contextualizers => src/frame/middleware/context}/generic-toc.js (100%) rename {middleware/contextualizers => src/frame/middleware/context}/glossaries.js (100%) rename {middleware/contextualizers => src/frame/middleware/context}/layout.js (100%) rename {middleware/contextualizers => src/frame/middleware/context}/product-examples.js (100%) rename {middleware/contextualizers => src/frame/middleware/context}/product-groups.js (100%) rename {middleware/contextualizers => src/frame/middleware/context}/whats-new-changelog.js (100%) rename {middleware => src/frame/middleware}/cookie-parser.js (100%) rename {middleware => src/frame/middleware}/fast-head.js (100%) rename {middleware => src/frame/middleware}/fastly-behavior.js (100%) rename {middleware => src/frame/middleware}/fastly-cache-test.js (100%) rename {middleware => src/frame/middleware}/favicons.js (100%) rename {middleware => src/frame/middleware}/find-page.js (100%) rename {middleware => src/frame/middleware}/halt-on-dropped-connection.js (100%) rename {middleware => src/frame/middleware}/handle-next-data-path.js (100%) rename {middleware => src/frame/middleware}/healthz.js (100%) rename {middleware => src/frame/middleware}/helmet.js (100%) rename {middleware => src/frame/middleware}/index.js (95%) rename {middleware => src/frame/middleware}/manifest-json.js (100%) rename {middleware => src/frame/middleware}/mock-va-portal.js (100%) rename {middleware => src/frame/middleware}/next.js (100%) rename {middleware => src/frame/middleware}/product-icons.js (100%) rename {middleware => src/frame/middleware}/reload-tree.js (100%) rename {middleware => src/frame/middleware}/remote-ip.js (100%) rename {middleware => src/frame/middleware}/render-page.js (100%) rename {middleware => src/frame/middleware}/robots.js (100%) rename {middleware => src/frame/middleware}/set-fastly-surrogate-key.js (100%) rename {middleware => src/frame/middleware}/timeout.js (100%) rename {middleware => src/frame/middleware}/trailing-slashes.js (100%) diff --git a/.github/workflows/azure-preview-env-deploy.yml b/.github/workflows/azure-preview-env-deploy.yml index 8d14be59cf41..78567b9e25fc 100644 --- a/.github/workflows/azure-preview-env-deploy.yml +++ b/.github/workflows/azure-preview-env-deploy.yml @@ -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 diff --git a/Dockerfile b/Dockerfile index 9a9cb50f3f5d..60889fdfd307 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/content/contributing/setting-up-your-environment-to-work-on-github-docs/creating-a-local-environment.md b/content/contributing/setting-up-your-environment-to-work-on-github-docs/creating-a-local-environment.md index aca9e4048e51..1447ab840b5f 100644 --- a/content/contributing/setting-up-your-environment-to-work-on-github-docs/creating-a-local-environment.md +++ b/content/contributing/setting-up-your-environment-to-work-on-github-docs/creating-a-local-environment.md @@ -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) diff --git a/contributing/development.md b/contributing/development.md index d033e5575bbe..fcbc66828cb3 100644 --- a/contributing/development.md +++ b/contributing/development.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: diff --git a/data/product-examples/README.md b/data/product-examples/README.md index b22df8c93800..4791fb3312c8 100644 --- a/data/product-examples/README.md +++ b/data/product-examples/README.md @@ -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. -2. User examples - See https://docs.github.com/en/sponsors#community-examples. +1. User examples + See https://docs.github.com/en/sponsors#community-examples. ## 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`. diff --git a/data/release-notes/enterprise-server/README.md b/data/release-notes/enterprise-server/README.md index a42d70f2070e..b8d0cca2767d 100644 --- a/data/release-notes/enterprise-server/README.md +++ b/data/release-notes/enterprise-server/README.md @@ -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 ## 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 enterprise-VERSION-release 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 diff --git a/data/release-notes/github-ae/README.md b/data/release-notes/github-ae/README.md index 22ffa477caa1..c65f5e468f3e 100644 --- a/data/release-notes/github-ae/README.md +++ b/data/release-notes/github-ae/README.md @@ -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 ## 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 diff --git a/middleware/README.md b/middleware/README.md deleted file mode 100644 index 353bcc99e124..000000000000 --- a/middleware/README.md +++ /dev/null @@ -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! \ No newline at end of file diff --git a/src/archives/middleware/archived-enterprise-versions-assets.js b/src/archives/middleware/archived-enterprise-versions-assets.js index dbb56590e83d..d7f902730b10 100644 --- a/src/archives/middleware/archived-enterprise-versions-assets.js +++ b/src/archives/middleware/archived-enterprise-versions-assets.js @@ -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 diff --git a/src/archives/middleware/archived-enterprise-versions.js b/src/archives/middleware/archived-enterprise-versions.js index d3f76872b034..15219290f0d8 100644 --- a/src/archives/middleware/archived-enterprise-versions.js +++ b/src/archives/middleware/archived-enterprise-versions.js @@ -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 } diff --git a/src/archives/scripts/warmup-remotejson.js b/src/archives/scripts/warmup-remotejson.js index 2269cf492212..6cc031746eef 100755 --- a/src/archives/scripts/warmup-remotejson.js +++ b/src/archives/scripts/warmup-remotejson.js @@ -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, diff --git a/src/archives/tests/deprecated-enterprise-versions.js b/src/archives/tests/deprecated-enterprise-versions.js index 6a11f7c8b6b9..e5c2d6ecb4d9 100644 --- a/src/archives/tests/deprecated-enterprise-versions.js +++ b/src/archives/tests/deprecated-enterprise-versions.js @@ -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 }) diff --git a/src/assets/middleware/dynamic-assets.js b/src/assets/middleware/dynamic-assets.js index 18023c03a721..071e3c806c1c 100644 --- a/src/assets/middleware/dynamic-assets.js +++ b/src/assets/middleware/dynamic-assets.js @@ -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. diff --git a/src/assets/middleware/static-asset-caching.js b/src/assets/middleware/static-asset-caching.js index 826ead77a568..876332c11481 100644 --- a/src/assets/middleware/static-asset-caching.js +++ b/src/assets/middleware/static-asset-caching.js @@ -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)) { diff --git a/src/assets/tests/dynamic-assets.js b/src/assets/tests/dynamic-assets.js index 85af617c6753..c1a1c2717a14 100644 --- a/src/assets/tests/dynamic-assets.js +++ b/src/assets/tests/dynamic-assets.js @@ -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', () => { diff --git a/src/assets/tests/static-assets-1.js b/src/assets/tests/static-assets-1.js index 9a001bf50691..5742774b4986 100644 --- a/src/assets/tests/static-assets-1.js +++ b/src/assets/tests/static-assets-1.js @@ -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 }) { diff --git a/src/content-linter/tests/category-pages.js b/src/content-linter/tests/category-pages.js index f238ae310dc5..03505601d848 100644 --- a/src/content-linter/tests/category-pages.js +++ b/src/content-linter/tests/category-pages.js @@ -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' diff --git a/src/dev-toc/generate.js b/src/dev-toc/generate.js index 4bc85ce5aae6..c58ba4fa697e 100755 --- a/src/dev-toc/generate.js +++ b/src/dev-toc/generate.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') diff --git a/src/events/middleware.js b/src/events/middleware.js index 266760596b3b..e043a55e2b5b 100644 --- a/src/events/middleware.js +++ b/src/events/middleware.js @@ -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' diff --git a/src/frame/lib/app.js b/src/frame/lib/app.js index 5a2c4418cc42..90ba00b49642 100644 --- a/src/frame/lib/app.js +++ b/src/frame/lib/app.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() diff --git a/middleware/get-remote-json.js b/src/frame/lib/get-remote-json.js similarity index 100% rename from middleware/get-remote-json.js rename to src/frame/lib/get-remote-json.js diff --git a/src/frame/middleware/README.md b/src/frame/middleware/README.md new file mode 100644 index 000000000000..e3f8c2b279f3 --- /dev/null +++ b/src/frame/middleware/README.md @@ -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 diff --git a/middleware/abort.js b/src/frame/middleware/abort.js similarity index 100% rename from middleware/abort.js rename to src/frame/middleware/abort.js diff --git a/middleware/api/index.js b/src/frame/middleware/api.js similarity index 100% rename from middleware/api/index.js rename to src/frame/middleware/api.js diff --git a/middleware/block-robots.js b/src/frame/middleware/block-robots.js similarity index 100% rename from middleware/block-robots.js rename to src/frame/middleware/block-robots.js diff --git a/middleware/build-info.js b/src/frame/middleware/build-info.js similarity index 100% rename from middleware/build-info.js rename to src/frame/middleware/build-info.js diff --git a/middleware/cache-control.js b/src/frame/middleware/cache-control.js similarity index 100% rename from middleware/cache-control.js rename to src/frame/middleware/cache-control.js diff --git a/middleware/categories-for-support.js b/src/frame/middleware/categories-for-support.js similarity index 100% rename from middleware/categories-for-support.js rename to src/frame/middleware/categories-for-support.js diff --git a/middleware/contextualizers/breadcrumbs.js b/src/frame/middleware/context/breadcrumbs.js similarity index 100% rename from middleware/contextualizers/breadcrumbs.js rename to src/frame/middleware/context/breadcrumbs.js diff --git a/middleware/context.js b/src/frame/middleware/context/context.js similarity index 100% rename from middleware/context.js rename to src/frame/middleware/context/context.js diff --git a/middleware/contextualizers/current-product-tree.js b/src/frame/middleware/context/current-product-tree.js similarity index 100% rename from middleware/contextualizers/current-product-tree.js rename to src/frame/middleware/context/current-product-tree.js diff --git a/middleware/contextualizers/generic-toc.js b/src/frame/middleware/context/generic-toc.js similarity index 100% rename from middleware/contextualizers/generic-toc.js rename to src/frame/middleware/context/generic-toc.js diff --git a/middleware/contextualizers/glossaries.js b/src/frame/middleware/context/glossaries.js similarity index 100% rename from middleware/contextualizers/glossaries.js rename to src/frame/middleware/context/glossaries.js diff --git a/middleware/contextualizers/layout.js b/src/frame/middleware/context/layout.js similarity index 100% rename from middleware/contextualizers/layout.js rename to src/frame/middleware/context/layout.js diff --git a/middleware/contextualizers/product-examples.js b/src/frame/middleware/context/product-examples.js similarity index 100% rename from middleware/contextualizers/product-examples.js rename to src/frame/middleware/context/product-examples.js diff --git a/middleware/contextualizers/product-groups.js b/src/frame/middleware/context/product-groups.js similarity index 100% rename from middleware/contextualizers/product-groups.js rename to src/frame/middleware/context/product-groups.js diff --git a/middleware/contextualizers/whats-new-changelog.js b/src/frame/middleware/context/whats-new-changelog.js similarity index 100% rename from middleware/contextualizers/whats-new-changelog.js rename to src/frame/middleware/context/whats-new-changelog.js diff --git a/middleware/cookie-parser.js b/src/frame/middleware/cookie-parser.js similarity index 100% rename from middleware/cookie-parser.js rename to src/frame/middleware/cookie-parser.js diff --git a/middleware/fast-head.js b/src/frame/middleware/fast-head.js similarity index 100% rename from middleware/fast-head.js rename to src/frame/middleware/fast-head.js diff --git a/middleware/fastly-behavior.js b/src/frame/middleware/fastly-behavior.js similarity index 100% rename from middleware/fastly-behavior.js rename to src/frame/middleware/fastly-behavior.js diff --git a/middleware/fastly-cache-test.js b/src/frame/middleware/fastly-cache-test.js similarity index 100% rename from middleware/fastly-cache-test.js rename to src/frame/middleware/fastly-cache-test.js diff --git a/middleware/favicons.js b/src/frame/middleware/favicons.js similarity index 100% rename from middleware/favicons.js rename to src/frame/middleware/favicons.js diff --git a/middleware/find-page.js b/src/frame/middleware/find-page.js similarity index 100% rename from middleware/find-page.js rename to src/frame/middleware/find-page.js diff --git a/middleware/halt-on-dropped-connection.js b/src/frame/middleware/halt-on-dropped-connection.js similarity index 100% rename from middleware/halt-on-dropped-connection.js rename to src/frame/middleware/halt-on-dropped-connection.js diff --git a/middleware/handle-next-data-path.js b/src/frame/middleware/handle-next-data-path.js similarity index 100% rename from middleware/handle-next-data-path.js rename to src/frame/middleware/handle-next-data-path.js diff --git a/middleware/healthz.js b/src/frame/middleware/healthz.js similarity index 100% rename from middleware/healthz.js rename to src/frame/middleware/healthz.js diff --git a/middleware/helmet.js b/src/frame/middleware/helmet.js similarity index 100% rename from middleware/helmet.js rename to src/frame/middleware/helmet.js diff --git a/middleware/index.js b/src/frame/middleware/index.js similarity index 95% rename from middleware/index.js rename to src/frame/middleware/index.js index 78a2794d364b..a72519af9476 100644 --- a/middleware/index.js +++ b/src/frame/middleware/index.js @@ -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' diff --git a/middleware/manifest-json.js b/src/frame/middleware/manifest-json.js similarity index 100% rename from middleware/manifest-json.js rename to src/frame/middleware/manifest-json.js diff --git a/middleware/mock-va-portal.js b/src/frame/middleware/mock-va-portal.js similarity index 100% rename from middleware/mock-va-portal.js rename to src/frame/middleware/mock-va-portal.js diff --git a/middleware/next.js b/src/frame/middleware/next.js similarity index 100% rename from middleware/next.js rename to src/frame/middleware/next.js diff --git a/middleware/product-icons.js b/src/frame/middleware/product-icons.js similarity index 100% rename from middleware/product-icons.js rename to src/frame/middleware/product-icons.js diff --git a/middleware/reload-tree.js b/src/frame/middleware/reload-tree.js similarity index 100% rename from middleware/reload-tree.js rename to src/frame/middleware/reload-tree.js diff --git a/middleware/remote-ip.js b/src/frame/middleware/remote-ip.js similarity index 100% rename from middleware/remote-ip.js rename to src/frame/middleware/remote-ip.js diff --git a/middleware/render-page.js b/src/frame/middleware/render-page.js similarity index 100% rename from middleware/render-page.js rename to src/frame/middleware/render-page.js diff --git a/middleware/robots.js b/src/frame/middleware/robots.js similarity index 100% rename from middleware/robots.js rename to src/frame/middleware/robots.js diff --git a/middleware/set-fastly-surrogate-key.js b/src/frame/middleware/set-fastly-surrogate-key.js similarity index 100% rename from middleware/set-fastly-surrogate-key.js rename to src/frame/middleware/set-fastly-surrogate-key.js diff --git a/middleware/timeout.js b/src/frame/middleware/timeout.js similarity index 100% rename from middleware/timeout.js rename to src/frame/middleware/timeout.js diff --git a/middleware/trailing-slashes.js b/src/frame/middleware/trailing-slashes.js similarity index 100% rename from middleware/trailing-slashes.js rename to src/frame/middleware/trailing-slashes.js diff --git a/src/languages/scripts/purge-fastly-edge-cache-per-language.js b/src/languages/scripts/purge-fastly-edge-cache-per-language.js index 22ff005dd090..9e2e359e4a8a 100755 --- a/src/languages/scripts/purge-fastly-edge-cache-per-language.js +++ b/src/languages/scripts/purge-fastly-edge-cache-per-language.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' /** diff --git a/src/languages/tests/frame.js b/src/languages/tests/frame.js index 98f0b9c11d3b..0362953861cb 100644 --- a/src/languages/tests/frame.js +++ b/src/languages/tests/frame.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' diff --git a/src/links/scripts/check-github-github-links.js b/src/links/scripts/check-github-github-links.js index fe4d1629b2b7..2003d9774673 100755 --- a/src/links/scripts/check-github-github-links.js +++ b/src/links/scripts/check-github-github-links.js @@ -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 = { diff --git a/src/links/scripts/rendered-content-link-checker.js b/src/links/scripts/rendered-content-link-checker.js index 33dbc9880824..741119c919aa 100755 --- a/src/links/scripts/rendered-content-link-checker.js +++ b/src/links/scripts/rendered-content-link-checker.js @@ -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 = { diff --git a/src/observability/lib/instrument-middleware.js b/src/observability/lib/instrument-middleware.js index c48404ea9009..0f5e572357ab 100644 --- a/src/observability/lib/instrument-middleware.js +++ b/src/observability/lib/instrument-middleware.js @@ -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. diff --git a/src/observability/middleware/handle-errors.js b/src/observability/middleware/handle-errors.js index d59f9ffc2f26..9a86efb8dcba 100644 --- a/src/observability/middleware/handle-errors.js +++ b/src/observability/middleware/handle-errors.js @@ -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')) diff --git a/src/pageinfo/middleware.js b/src/pageinfo/middleware.js index f75eb11a713a..b7825a198aac 100644 --- a/src/pageinfo/middleware.js +++ b/src/pageinfo/middleware.js @@ -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' diff --git a/src/pageinfo/tests/pageinfo.js b/src/pageinfo/tests/pageinfo.js index 2c5a66055ab1..d53a4a1a691b 100644 --- a/src/pageinfo/tests/pageinfo.js +++ b/src/pageinfo/tests/pageinfo.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 })}` diff --git a/src/redirects/README.md b/src/redirects/README.md index e0a1f07ecf32..c3d459637ebc 100644 --- a/src/redirects/README.md +++ b/src/redirects/README.md @@ -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 diff --git a/src/redirects/middleware/handle-redirects.js b/src/redirects/middleware/handle-redirects.js index 93cd646d9fc1..d04d4991bbf7 100644 --- a/src/redirects/middleware/handle-redirects.js +++ b/src/redirects/middleware/handle-redirects.js @@ -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 diff --git a/src/redirects/middleware/language-code-redirects.js b/src/redirects/middleware/language-code-redirects.js index 6b9fa753b9ee..d1150b2669d7 100644 --- a/src/redirects/middleware/language-code-redirects.js +++ b/src/redirects/middleware/language-code-redirects.js @@ -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 || []) diff --git a/src/rest/api/anchor-redirect.js b/src/rest/api/anchor-redirect.js index 864f3d955b66..1031be664415 100644 --- a/src/rest/api/anchor-redirect.js +++ b/src/rest/api/anchor-redirect.js @@ -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( diff --git a/src/rest/tests/api.js b/src/rest/tests/api.js index e9bcbf327007..7d5d3229defb 100644 --- a/src/rest/tests/api.js +++ b/src/rest/tests/api.js @@ -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( diff --git a/src/search/middleware/search.js b/src/search/middleware/search.js index a9fad9240180..46740034e28a 100644 --- a/src/search/middleware/search.js +++ b/src/search/middleware/search.js @@ -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' diff --git a/src/search/tests/rendering.js b/src/search/tests/rendering.js index ba1dd1b65eae..613e51cc376d 100644 --- a/src/search/tests/rendering.js +++ b/src/search/tests/rendering.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( diff --git a/src/shielding/README.md b/src/shielding/README.md index 5fa156f5379a..b7fe08c4993f 100644 --- a/src/shielding/README.md +++ b/src/shielding/README.md @@ -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 diff --git a/src/shielding/middleware/handle-invalid-nextjs-paths.js b/src/shielding/middleware/handle-invalid-nextjs-paths.js index 4b6eebee206a..7601968d7dd7 100644 --- a/src/shielding/middleware/handle-invalid-nextjs-paths.js +++ b/src/shielding/middleware/handle-invalid-nextjs-paths.js @@ -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' diff --git a/src/shielding/middleware/handle-invalid-paths.js b/src/shielding/middleware/handle-invalid-paths.js index 76c7369a5b6a..ee9b39a9f7bc 100644 --- a/src/shielding/middleware/handle-invalid-paths.js +++ b/src/shielding/middleware/handle-invalid-paths.js @@ -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([ diff --git a/src/shielding/middleware/handle-invalid-query-string-values.js b/src/shielding/middleware/handle-invalid-query-string-values.js index 6d21e783ebd3..ecb26fc33288 100644 --- a/src/shielding/middleware/handle-invalid-query-string-values.js +++ b/src/shielding/middleware/handle-invalid-query-string-values.js @@ -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' diff --git a/src/shielding/middleware/handle-invalid-query-strings.js b/src/shielding/middleware/handle-invalid-query-strings.js index 171f48aec8c1..64a96680cfce 100644 --- a/src/shielding/middleware/handle-invalid-query-strings.js +++ b/src/shielding/middleware/handle-invalid-query-strings.js @@ -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' diff --git a/src/shielding/middleware/handle-old-next-data-paths.js b/src/shielding/middleware/handle-old-next-data-paths.js index d7f80e5fe98d..432e1a03f4e7 100644 --- a/src/shielding/middleware/handle-old-next-data-paths.js +++ b/src/shielding/middleware/handle-old-next-data-paths.js @@ -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/')) { diff --git a/src/shielding/middleware/rate-limit.js b/src/shielding/middleware/rate-limit.js index 7ca847e305ff..146c4283ca10 100644 --- a/src/shielding/middleware/rate-limit.js +++ b/src/shielding/middleware/rate-limit.js @@ -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 diff --git a/src/shielding/tests/shielding.js b/src/shielding/tests/shielding.js index 7eb3e4d43fb9..7a55b9d0f8e0 100644 --- a/src/shielding/tests/shielding.js +++ b/src/shielding/tests/shielding.js @@ -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', () => { diff --git a/src/webhooks/middleware/webhooks.js b/src/webhooks/middleware/webhooks.js index 8faccaf272d8..327cfd160171 100644 --- a/src/webhooks/middleware/webhooks.js +++ b/src/webhooks/middleware/webhooks.js @@ -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() diff --git a/src/webhooks/tests/api.js b/src/webhooks/tests/api.js index 43278232e8b8..fd582a6d30b5 100644 --- a/src/webhooks/tests/api.js +++ b/src/webhooks/tests/api.js @@ -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', () => { diff --git a/src/workflows/purge-fastly-edge-cache.js b/src/workflows/purge-fastly-edge-cache.js index 2f9639e20360..be5a33a093f2 100755 --- a/src/workflows/purge-fastly-edge-cache.js +++ b/src/workflows/purge-fastly-edge-cache.js @@ -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* diff --git a/tests/helpers/caching-headers.js b/tests/helpers/caching-headers.js index 807a9ce65946..df5df8365489 100644 --- a/tests/helpers/caching-headers.js +++ b/tests/helpers/caching-headers.js @@ -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() diff --git a/tests/rendering/block-robots.js b/tests/rendering/block-robots.js index 412ae746dcd3..92890972f884 100644 --- a/tests/rendering/block-robots.js +++ b/tests/rendering/block-robots.js @@ -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' diff --git a/tests/rendering/favicons.js b/tests/rendering/favicons.js index 6aad24093be0..3ad985228c6a 100644 --- a/tests/rendering/favicons.js +++ b/tests/rendering/favicons.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', () => { diff --git a/tests/rendering/manifest.js b/tests/rendering/manifest.js index 9b9ea5896a1c..b81459672453 100644 --- a/tests/rendering/manifest.js +++ b/tests/rendering/manifest.js @@ -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', () => { diff --git a/tests/rendering/robots-txt.js b/tests/rendering/robots-txt.js index b22c3bf0e123..dbb575e360ad 100644 --- a/tests/rendering/robots-txt.js +++ b/tests/rendering/robots-txt.js @@ -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', () => { diff --git a/tests/rendering/server.js b/tests/rendering/server.js index 4d66da112ff7..67ae339a7d8c 100644 --- a/tests/rendering/server.js +++ b/tests/rendering/server.js @@ -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' diff --git a/tests/unit/find-page-middleware.js b/tests/unit/find-page-middleware.js index cbc59cf56744..4c9ba3516afb 100644 --- a/tests/unit/find-page-middleware.js +++ b/tests/unit/find-page-middleware.js @@ -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)) diff --git a/tests/unit/get-remote-json.js b/tests/unit/get-remote-json.js index 925666306b1b..731dfaaad50e 100644 --- a/tests/unit/get-remote-json.js +++ b/tests/unit/get-remote-json.js @@ -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' /** *