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

22 lines
544 B
JavaScript

const defaultResponse = 'User-agent: *'
const disallowAll = `User-agent: *
Disallow: /`
export default function robots(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)
}
return res.send(defaultResponse)
}