Skip to content

Commit 8fad07b

Browse files
authored
Merge pull request #38869 from github/repo-sync
Repo sync
2 parents 1ead119 + c86a000 commit 8fad07b

File tree

17 files changed

+508
-312
lines changed

17 files changed

+508
-312
lines changed

package-lock.json

Lines changed: 430 additions & 282 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@
269269
"dereference-json-schema": "^0.2.1",
270270
"dotenv": "^16.4.7",
271271
"escape-string-regexp": "5.0.0",
272-
"express": "4.21.2",
272+
"express": "^5.1.0",
273273
"fastest-levenshtein": "1.0.16",
274274
"file-type": "21.0.0",
275275
"flat": "^6.0.1",
@@ -349,7 +349,7 @@
349349
"@types/cookie": "0.6.0",
350350
"@types/cookie-parser": "1.4.8",
351351
"@types/event-to-promise": "^0.7.5",
352-
"@types/express": "4.17.21",
352+
"@types/express": "^5.0.3",
353353
"@types/imurmurhash": "^0.1.4",
354354
"@types/js-cookie": "^3.0.6",
355355
"@types/js-yaml": "^4.0.9",

src/frame/middleware/api.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,15 @@ router.get('/cookies', (req, res) => {
6565
const cookies = {
6666
isStaff: Boolean(req.cookies?.staffonly?.startsWith('yes')) || false,
6767
}
68-
return res.json(cookies)
68+
res.json(cookies)
6969
})
7070

71-
router.get('*', (req, res) => {
71+
// Handle root /api requests
72+
router.get('/', (req, res) => {
73+
res.status(404).json({ error: `${req.path} not found` })
74+
})
75+
76+
router.get('/*path', (req, res) => {
7277
res.status(404).json({ error: `${req.path} not found` })
7378
})
7479

src/frame/middleware/build-info.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ export default function buildInfo(req: Request, res: Response) {
88
res.type('text/plain')
99
noCacheControl(res)
1010
if (!BUILD_SHA) {
11-
return res.status(404).send('Not known')
11+
res.status(404).send('Not known')
12+
return
1213
}
13-
return res.send(`${BUILD_SHA}`)
14+
res.send(`${BUILD_SHA}`)
1415
}

src/frame/middleware/fast-head.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export default function fastHead(req: ExtendedRequest, res: Response, next: Next
1212
// this and allow the CDN to hold on to it.
1313
defaultCacheControl(res)
1414

15-
return res.status(200).send('')
15+
res.status(200).send('')
16+
return
1617
}
1718
next()
1819
}

src/frame/middleware/fastly-cache-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import crypto from 'crypto'
1212

1313
const router = express.Router()
1414

15-
router.get('/*', function (req, res) {
15+
router.get('/*path', function (req, res) {
1616
// If X-CacheTest-Error is set, simulate the site being down (regardless of URL)
1717
if (req.get('X-CacheTest-Error')) {
1818
res.status(parseInt(req.get('X-CacheTest-Error') as string)).end()

src/frame/middleware/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ export default function (app: Express) {
250250

251251
// Specifically deal with HEAD requests before doing the slower
252252
// full page rendering.
253-
app.head('/*', fastHead)
253+
app.head('/*path', fastHead)
254254

255255
// *** Preparation for render-page: contextualizers ***
256256
app.use(asyncMiddleware(secretScanning))
@@ -282,7 +282,7 @@ export default function (app: Express) {
282282
app.use(haltOnDroppedConnection)
283283

284284
// *** Rendering, must go almost last ***
285-
app.get('/*', asyncMiddleware(renderPage))
285+
app.get('/*path', asyncMiddleware(renderPage))
286286

287287
// *** Error handling, must go last ***
288288
app.use(handleErrors)

src/frame/middleware/mock-va-portal.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ export default function mockVaPortal(req: ExtendedRequest, res: Response, next:
5858

5959
if (req.url.startsWith('/iframe/docs_va')) {
6060
res.removeHeader('content-security-policy')
61-
return res.status(200).type('text/html').send(HTML)
61+
res.status(200).type('text/html').send(HTML)
62+
return
6263
}
6364

6465
next()

src/frame/middleware/render-page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export default async function renderPage(req: ExtendedRequest, res: Response) {
108108
// It's important to not use `src/pages/404.txt` (or `/404` as the path)
109109
// here because then it will set the wrong Cache-Control header.
110110
tempReq.url = '/_notfound'
111-
tempReq.path = '/_notfound'
111+
Object.defineProperty(tempReq, 'path', { value: '/_notfound', writable: true })
112112
tempReq.cookies = {}
113113
tempReq.headers = {}
114114
// By default, since the lookup for a `src/pages/*.tsx` file will work,

src/frame/middleware/robots.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ export default function robots(req: ExtendedRequest, res: Response, next: NextFu
2323
req.hostname === 'docs.github.com' ||
2424
req.hostname === '127.0.0.1'
2525
) {
26-
return res.send(defaultResponse)
26+
res.send(defaultResponse)
27+
return
2728
}
2829

29-
return res.send(disallowAll)
30+
res.send(disallowAll)
3031
}

0 commit comments

Comments
 (0)