1
0
mirror of synced 2025-12-21 10:57:10 -05:00
Files
docs/middleware/redirects/help-to-docs.js
Kevin Heis 8a56437c93 Pretty format (#20352)
* Update prettier flow to include JS

* Run prettier

* ...run prettier
2021-07-14 14:35:01 -07:00

19 lines
515 B
JavaScript

import { URL } from 'url'
import patterns from '../../lib/patterns.js'
// redirect help.github.com requests to docs.github.com
export default function helpToDocs(req, res, next) {
if (req.hostname === 'help.github.com') {
// prevent open redirect security vulnerability
const path = req.originalUrl.replace(patterns.multipleSlashes, '/')
const url = new URL(path, 'https://docs.github.com')
const newURL = url.toString()
return res.redirect(301, newURL)
} else {
return next()
}
}