1
0
mirror of synced 2025-12-26 14:02:45 -05:00
Files
docs/middleware/redirects/help-to-docs.js
Vanessa Yuen 3df90fc9b8 Hello git history spelunker!
Are you looking for something? Here is all of the GitHub Docs history in one single commit. Enjoy! 🎉
2020-09-27 14:10:11 +02:00

19 lines
514 B
JavaScript

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