1
0
mirror of synced 2025-12-22 03:16:52 -05:00
Files
docs/middleware/redirects/help-to-docs.js
James M. Greene c940dcd98b Middleware overhaul! (#18218)
* Middleware overhaul!

- Remove unnecessary 'async' keywords from middleware functions
- Ensure all middleware functions we create have names
- Wrap the method contents of all async middleware functions in a try-catch+next(error) pattern

* Use asyncMiddleware wrapper instead of try-catch+next(error) pattern

* Remove unnecessary try-catch+next(error) pattern from context middleware
2021-03-11 01:12:41 +00:00

19 lines
525 B
JavaScript

const { URL } = require('url')
const patterns = require('../../lib/patterns')
// redirect help.github.com requests to docs.github.com
module.exports = 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()
}
}