Skip to content

Commit

Permalink
Merge pull request #33724 from github/repo-sync
Browse files Browse the repository at this point in the history
Repo sync
  • Loading branch information
docs-bot committed Jun 26, 2024
2 parents 3b9d172 + 53b5f97 commit 6879e0b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 38 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@
"eslint-plugin-jsx-a11y": "^6.9.0",
"eslint-plugin-primer-react": "^5.3.0",
"event-to-promise": "^0.8.0",
"graphql": "^16.8.1",
"graphql": "^16.9.0",
"http-status-code": "^2.1.0",
"husky": "^9.0.8",
"json-schema-merge-allof": "^0.8.1",
Expand All @@ -376,7 +376,7 @@
"robots-parser": "^3.0.0",
"sass": "^1.77.1",
"start-server-and-test": "^2.0.3",
"typescript": "^5.4.4",
"typescript": "^5.5.2",
"unist-util-remove": "^4.0.0",
"unist-util-visit-parents": "6.0.1",
"vitest": "1.6.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import fs from 'fs/promises'

import type { Response, NextFunction } from 'express'
import sharp from 'sharp'

import { assetCacheControl, defaultCacheControl } from '#src/frame/middleware/cache-control.js'
import type { ExtendedRequest } from '@/types'
import { assetCacheControl, defaultCacheControl } from '@/frame/middleware/cache-control.js'
import {
setFastlySurrogateKey,
SURROGATE_ENUMS,
} from '#src/frame/middleware/set-fastly-surrogate-key.js'
} from '@/frame/middleware/set-fastly-surrogate-key.js'

/**
* This is the indicator that is a virtual part of the URL.
Expand Down Expand Up @@ -37,7 +39,11 @@ const maxWidthPathPartRegex = /\/mw-(\d+)\//
*/
const VALID_MAX_WIDTHS = [1440, 1000]

export default async function dynamicAssets(req, res, next) {
export default async function dynamicAssets(
req: ExtendedRequest,
res: Response,
next: NextFunction,
) {
if (!req.url.startsWith('/assets/')) return next()

if (!(req.method === 'GET' || req.method === 'HEAD')) {
Expand Down Expand Up @@ -88,6 +94,7 @@ export default async function dynamicAssets(req, res, next) {

if (maxWidth) {
const { width } = await image.metadata()
if (width === undefined) throw new Error('image metadata does not have a width')
if (width > maxWidth) {
image.resize({ width: maxWidth })
}
Expand Down Expand Up @@ -140,7 +147,7 @@ export default async function dynamicAssets(req, res, next) {
assetCacheControl(res)
return res.type('image/webp').send(buffer)
} catch (error) {
if (error.code !== 'ENOENT') {
if (error instanceof Error && (error as any).code !== 'ENOENT') {
throw error
}
}
Expand All @@ -166,7 +173,7 @@ export default async function dynamicAssets(req, res, next) {
res.status(404).type('text/plain').send('Asset not found')
}

function deconstructImageURL(url) {
function deconstructImageURL(url: string) {
let error
let maxWidth
const match = url.match(maxWidthPathPartRegex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { describe, expect, test, vi } from 'vitest'
import sharp from 'sharp'
import { fileTypeFromBuffer } from 'file-type'

import { SURROGATE_ENUMS } from '#src/frame/middleware/set-fastly-surrogate-key.js'
import { get, head } from '#src/tests/helpers/e2etest.js'
import { SURROGATE_ENUMS } from '@/frame/middleware/set-fastly-surrogate-key.js'
import { get, head } from '@/tests/helpers/e2etest.js'

describe('dynamic assets', () => {
vi.setConfig({ testTimeout: 3 * 60 * 1000 })
Expand All @@ -15,7 +15,10 @@ describe('dynamic assets', () => {
})
expect(res.statusCode).toBe(200)
expect(res.headers['content-type']).toBe('image/webp')
const { mime } = await fileTypeFromBuffer(res.body)

const fileTypeResult = await fileTypeFromBuffer(res.body)
if (!fileTypeResult) throw new Error('fileTypeFromBuffer failed')
const { mime } = fileTypeResult
expect(mime).toBe('image/webp')
})

Expand Down
14 changes: 0 additions & 14 deletions src/frame/middleware/fastly-behavior.js

This file was deleted.

7 changes: 1 addition & 6 deletions src/frame/middleware/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ import setStaticAssetCaching from '@/assets/middleware/static-asset-caching'
import fastHead from './fast-head'
import fastlyCacheTest from './fastly-cache-test'
import trailingSlashes from './trailing-slashes'
import fastlyBehavior from './fastly-behavior.js'
import mockVaPortal from './mock-va-portal.js'
import dynamicAssets from '@/assets/middleware/dynamic-assets.js'
import dynamicAssets from '@/assets/middleware/dynamic-assets'
import contextualizeSearch from '@/search/middleware/contextualize.js'
import shielding from '@/shielding/middleware'
import tracking from '@/tracking/middleware'
Expand Down Expand Up @@ -205,10 +204,6 @@ export default function (app: Express) {
app.use(cookieParser)
app.use(express.json())

if (ENABLE_FASTLY_TESTING) {
app.use(fastlyBehavior) // FOR TESTING.
}

if (process.env.NODE_ENV === 'development') {
app.use(mockVaPortal) // FOR TESTING.
}
Expand Down

0 comments on commit 6879e0b

Please sign in to comment.