Skip to content

Commit

Permalink
Migrate middleware directory to src (#45701)
Browse files Browse the repository at this point in the history
  • Loading branch information
heiskr authored Nov 6, 2023
1 parent 6236b81 commit 7586a1a
Show file tree
Hide file tree
Showing 93 changed files with 91 additions and 99 deletions.
1 change: 0 additions & 1 deletion .github/workflows/azure-preview-env-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion contributing/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
16 changes: 9 additions & 7 deletions data/product-examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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`.

Expand Down
6 changes: 3 additions & 3 deletions data/release-notes/enterprise-server/README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions data/release-notes/github-ae/README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

Expand Down
12 changes: 0 additions & 12 deletions middleware/README.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/archives/middleware/archived-enterprise-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion src/archives/scripts/warmup-remotejson.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/archives/tests/deprecated-enterprise-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })

Expand Down
4 changes: 2 additions & 2 deletions src/assets/middleware/dynamic-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/assets/middleware/static-asset-caching.js
Original file line number Diff line number Diff line change
@@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion src/assets/tests/dynamic-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/assets/tests/static-assets-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand Down
2 changes: 1 addition & 1 deletion src/content-linter/tests/category-pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
2 changes: 1 addition & 1 deletion src/dev-toc/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion src/events/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
2 changes: 1 addition & 1 deletion src/frame/lib/app.js
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions src/frame/middleware/README.md
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 10 additions & 10 deletions middleware/index.js → src/frame/middleware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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'

/**
Expand Down
2 changes: 1 addition & 1 deletion src/languages/tests/frame.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion src/links/scripts/check-github-github-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
4 changes: 2 additions & 2 deletions src/links/scripts/rendered-content-link-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion src/observability/lib/instrument-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Loading

0 comments on commit 7586a1a

Please sign in to comment.