* 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
19 lines
525 B
JavaScript
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()
|
|
}
|
|
}
|