1
0
mirror of synced 2025-12-21 10:57:10 -05:00
Files
docs/middleware/robots.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

39 lines
1.1 KiB
JavaScript

const languages = require('../lib/languages')
const products = require('../lib/all-products')
let defaultResponse = 'User-agent: *'
const disallowAll = `User-agent: *
Disallow: /`
module.exports = function (req, res, next) {
if (req.path !== '/robots.txt') return next()
res.type('text/plain')
// remove subdomain from host
// docs-internal-12345--branch-name.herokuapp.com -> herokuapp.com
const rootDomain = req.hostname.split('.').slice(1).join('.')
// prevent crawlers from indexing staging apps
if (rootDomain === 'herokuapp.com') {
return res.send(disallowAll)
}
// Disallow crawling of WIP localized content
Object.values(languages)
.filter(language => language.wip)
.forEach(language => {
defaultResponse = defaultResponse.concat(`\nDisallow: /${language.code}\nDisallow: /${language.code}/*\n`)
})
// Disallow crawling of WIP products
Object.values(products)
.filter(product => product.wip)
.forEach(product => {
defaultResponse = defaultResponse.concat(`\nDisallow: /*${product.href}\nDisallow: /*/enterprise/*/user${product.href}`)
})
return res.send(defaultResponse)
}