Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repo sync #32847

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@
"@types/imurmurhash": "^0.1.4",
"@types/js-cookie": "^3.0.6",
"@types/lodash": "^4.17.0",
"@types/morgan": "1.9.9",
"@types/react": "18.3.1",
"@types/react-dom": "^18.3.0",
"@types/tcp-port-used": "1.0.4",
Expand Down
2 changes: 1 addition & 1 deletion src/frame/lib/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import express from 'express'
import middleware from '@/frame/middleware/index.js'
import middleware from '@/frame/middleware'

function createApp() {
const app = express()
Expand Down
55 changes: 29 additions & 26 deletions src/frame/middleware/index.js → src/frame/middleware/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,89 +2,92 @@ import fs from 'fs'
import path from 'path'

import express from 'express'
import type { NextFunction, Request, Response, Express } from 'express'

import haltOnDroppedConnection from './halt-on-dropped-connection.js'
import abort from './abort.js'
import timeout from './timeout.js'
import morgan from 'morgan'
import datadog from '#src/observability/middleware/connect-datadog.js'
import datadog from '@/observability/middleware/connect-datadog.js'
import helmet from './helmet.js'
import cookieParser from './cookie-parser.js'
import {
setDefaultFastlySurrogateKey,
setLanguageFastlySurrogateKey,
} from './set-fastly-surrogate-key.js'
import handleErrors from '#src/observability/middleware/handle-errors.js'
import handleErrors from '@/observability/middleware/handle-errors.js'
import handleNextDataPath from './handle-next-data-path.js'
import detectLanguage from '#src/languages/middleware/detect-language.js'
import detectLanguage from '@/languages/middleware/detect-language.js'
import reloadTree from './reload-tree.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 shortVersions from '@/versions/middleware/short-versions.js'
import languageCodeRedirects from '@/redirects/middleware/language-code-redirects.js'
import handleRedirects from '@/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 archivedEnterpriseVersionsAssets from '@/archives/middleware/archived-enterprise-versions-assets.js'
import api from './api.js'
import healthz from './healthz.js'
import productIcons from './product-icons.js'
import manifestJson from './manifest-json.js'
import remoteIP from './remote-ip.js'
import buildInfo from './build-info.js'
import archivedEnterpriseVersions from '#src/archives/middleware/archived-enterprise-versions.js'
import archivedEnterpriseVersions from '@/archives/middleware/archived-enterprise-versions.js'
import robots from './robots.js'
import earlyAccessLinks from '#src/early-access/middleware/early-access-links.js'
import earlyAccessLinks from '@/early-access/middleware/early-access-links.js'
import categoriesForSupport from './categories-for-support.js'
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 triggerError from '@/observability/middleware/trigger-error.js'
import secretScanning from '@/secret-scanning/middleware/secret-scanning.js'
import ghesReleaseNotes from '@/release-notes/middleware/ghes-release-notes.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 renderProductName from './context/render-product-name.js'
import features from '#src/versions/middleware/features.js'
import features from '@/versions/middleware/features.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 featuredLinks from '@/landings/middleware/featured-links.js'
import learningTrack from '@/learning-track/middleware/learning-track.js'
import next from './next.js'
import renderPage from './render-page.js'
import assetPreprocessing from '#src/assets/middleware/asset-preprocessing.js'
import archivedAssetRedirects from '#src/archives/middleware/archived-asset-redirects.js'
import assetPreprocessing from '@/assets/middleware/asset-preprocessing.js'
import archivedAssetRedirects from '@/archives/middleware/archived-asset-redirects.js'
import favicons from './favicons.js'
import setStaticAssetCaching from '#src/assets/middleware/static-asset-caching.js'
import setStaticAssetCaching from '@/assets/middleware/static-asset-caching.js'
import fastHead from './fast-head.js'
import fastlyCacheTest from './fastly-cache-test.js'
import trailingSlashes from './trailing-slashes.js'
import fastlyBehavior from './fastly-behavior.js'
import mockVaPortal from './mock-va-portal.js'
import dynamicAssets from '#src/assets/middleware/dynamic-assets.js'
import contextualizeSearch from '#src/search/middleware/contextualize.js'
import shielding from '#src/shielding/middleware/index.js'
import tracking from '#src/tracking/middleware/index.js'
import dynamicAssets from '@/assets/middleware/dynamic-assets.js'
import contextualizeSearch from '@/search/middleware/contextualize.js'
import shielding from '@/shielding/middleware/index.js'
import tracking from '@/tracking/middleware/index.js'

const { DEPLOYMENT_ENV, NODE_ENV } = process.env
const isTest = NODE_ENV === 'test' || process.env.GITHUB_ACTIONS === 'true'

// By default, logging each request (with morgan), is on. And by default
// it's off if you're in a production environment or running automated tests.
// But if you set the env var, that takes precedence.
const ENABLE_DEV_LOGGING = JSON.parse(
process.env.ENABLE_DEV_LOGGING || !(DEPLOYMENT_ENV === 'azure' || isTest),
const ENABLE_DEV_LOGGING = Boolean(
process.env.ENABLE_DEV_LOGGING
? JSON.parse(process.env.ENABLE_DEV_LOGGING)
: !(DEPLOYMENT_ENV === 'azure' || isTest),
)

const ENABLE_FASTLY_TESTING = JSON.parse(process.env.ENABLE_FASTLY_TESTING || 'false')

// Catch unhandled promise rejections and passing them to Express's error handler
// https://medium.com/@Abazhenov/using-async-await-in-express-with-node-8-b8af872c0016
const asyncMiddleware = (fn) => (req, res, next) => {
const asyncMiddleware = (fn: Function) => (req: Request, res: Response, next: NextFunction) => {
Promise.resolve(fn(req, res, next)).catch(next)
}

export default function (app) {
export default function (app: Express) {
// *** Request connection management ***
if (!isTest) app.use(timeout)
app.use(abort)
Expand Down
Loading