* 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
22 lines
547 B
JavaScript
22 lines
547 B
JavaScript
const defaultResponse = 'User-agent: *'
|
|
|
|
const disallowAll = `User-agent: *
|
|
Disallow: /`
|
|
|
|
module.exports = 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)
|
|
}
|