MCPcopy Index your code
hub / github.com/github/docs / trailingSlashes

Function trailingSlashes

middleware/trailing-slashes.js:3–21  ·  view source on GitHub ↗
(req, res, next)

Source from the content-addressed store, hash-verified

1import { defaultCacheControl } from './cache-control.js'
2
3export default function trailingSlashes(req, res, next) {
4 if (req.method === 'GET' || req.method === 'HEAD' || req.method === 'OPTIONS') {
5 const split = req.url.split('?')
6 let pathname = split.shift()
7 if (pathname !== '/' && pathname.endsWith('/')) {
8 while (pathname.endsWith('/')) {
9 pathname = pathname.slice(0, pathname.length - 1)
10 }
11 let url = pathname
12 if (split.length) {
13 url += `?${split.join('?')}`
14 }
15 defaultCacheControl(res)
16 return res.redirect(301, url)
17 }
18 }
19
20 next()
21}

Callers

nothing calls this directly

Calls 2

defaultCacheControlFunction · 0.90
nextFunction · 0.50

Tested by

no test coverage detected