Stop indexing /about/peertube

This commit is contained in:
Chocobozzz 2021-10-08 11:06:02 +02:00
parent 32e06ca4de
commit 42cc1887af
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
5 changed files with 33 additions and 2 deletions

View File

@ -5,12 +5,12 @@ import { join } from 'path'
import { logger } from '@server/helpers/logger' import { logger } from '@server/helpers/logger'
import { CONFIG } from '@server/initializers/config' import { CONFIG } from '@server/initializers/config'
import { Hooks } from '@server/lib/plugins/hooks' import { Hooks } from '@server/lib/plugins/hooks'
import { HttpStatusCode } from '@shared/models'
import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '@shared/core-utils/i18n' import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '@shared/core-utils/i18n'
import { HttpStatusCode } from '@shared/models'
import { root } from '../helpers/core-utils' import { root } from '../helpers/core-utils'
import { STATIC_MAX_AGE } from '../initializers/constants' import { STATIC_MAX_AGE } from '../initializers/constants'
import { ClientHtml, sendHTML, serveIndexHTML } from '../lib/client-html' import { ClientHtml, sendHTML, serveIndexHTML } from '../lib/client-html'
import { asyncMiddleware, embedCSP } from '../middlewares' import { asyncMiddleware, disableRobots, embedCSP } from '../middlewares'
const clientsRouter = express.Router() const clientsRouter = express.Router()
@ -81,6 +81,12 @@ clientsRouter.use('/client/*', (req: express.Request, res: express.Response) =>
res.status(HttpStatusCode.NOT_FOUND_404).end() res.status(HttpStatusCode.NOT_FOUND_404).end()
}) })
// No index exceptions
clientsRouter.all('/about/peertube',
disableRobots,
asyncMiddleware(serveIndexHTML)
)
// Always serve index client page (the client is a single page application, let it handle routing) // Always serve index client page (the client is a single page application, let it handle routing)
// Try to provide the right language index.html // Try to provide the right language index.html
clientsRouter.use('/(:language)?', asyncMiddleware(serveIndexHTML)) clientsRouter.use('/(:language)?', asyncMiddleware(serveIndexHTML))

View File

@ -69,6 +69,7 @@ staticRouter.get('/robots.txt',
cacheRoute(ROUTE_CACHE_LIFETIME.ROBOTS), cacheRoute(ROUTE_CACHE_LIFETIME.ROBOTS),
(_, res: express.Response) => { (_, res: express.Response) => {
res.type('text/plain') res.type('text/plain')
return res.send(CONFIG.INSTANCE.ROBOTS) return res.send(CONFIG.INSTANCE.ROBOTS)
} }
) )

View File

@ -4,6 +4,7 @@ export * from './activitypub'
export * from './async' export * from './async'
export * from './auth' export * from './auth'
export * from './pagination' export * from './pagination'
export * from './robots'
export * from './servers' export * from './servers'
export * from './sort' export * from './sort'
export * from './user-right' export * from './user-right'

View File

@ -0,0 +1,13 @@
import express from 'express'
function disableRobots (req: express.Request, res: express.Response, next: express.NextFunction) {
res.setHeader('X-Robots-Tag', 'noindex')
return next()
}
// ---------------------------------------------------------------------------
export {
disableRobots
}

View File

@ -482,6 +482,16 @@ describe('Test a client controllers', function () {
} }
} }
}) })
it('Should add noindex header for some paths', async function () {
const paths = [ '/about/peertube' ]
for (const path of paths) {
const { headers } = await makeHTMLRequest(servers[0].url, path)
expect(headers['x-robots-tag']).to.equal('noindex')
}
})
}) })
describe('Embed HTML', function () { describe('Embed HTML', function () {