aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-10-08 11:06:02 +0200
committerChocobozzz <me@florianbigard.com>2021-10-11 09:37:26 +0200
commit42cc1887afc80e10ff40675621fe683c76537a18 (patch)
tree6409fb274d881e097095de9231e9be66199a2436
parent32e06ca4de8480e3b6d4542ef5cd7381b3795465 (diff)
downloadPeerTube-42cc1887afc80e10ff40675621fe683c76537a18.tar.gz
PeerTube-42cc1887afc80e10ff40675621fe683c76537a18.tar.zst
PeerTube-42cc1887afc80e10ff40675621fe683c76537a18.zip
Stop indexing /about/peertube
-rw-r--r--server/controllers/client.ts10
-rw-r--r--server/controllers/static.ts1
-rw-r--r--server/middlewares/index.ts1
-rw-r--r--server/middlewares/robots.ts13
-rw-r--r--server/tests/client.ts10
5 files changed, 33 insertions, 2 deletions
diff --git a/server/controllers/client.ts b/server/controllers/client.ts
index d81e35ec3..cdc556da2 100644
--- a/server/controllers/client.ts
+++ b/server/controllers/client.ts
@@ -5,12 +5,12 @@ import { join } from 'path'
5import { logger } from '@server/helpers/logger' 5import { logger } from '@server/helpers/logger'
6import { CONFIG } from '@server/initializers/config' 6import { CONFIG } from '@server/initializers/config'
7import { Hooks } from '@server/lib/plugins/hooks' 7import { Hooks } from '@server/lib/plugins/hooks'
8import { HttpStatusCode } from '@shared/models'
9import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '@shared/core-utils/i18n' 8import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '@shared/core-utils/i18n'
9import { HttpStatusCode } from '@shared/models'
10import { root } from '../helpers/core-utils' 10import { root } from '../helpers/core-utils'
11import { STATIC_MAX_AGE } from '../initializers/constants' 11import { STATIC_MAX_AGE } from '../initializers/constants'
12import { ClientHtml, sendHTML, serveIndexHTML } from '../lib/client-html' 12import { ClientHtml, sendHTML, serveIndexHTML } from '../lib/client-html'
13import { asyncMiddleware, embedCSP } from '../middlewares' 13import { asyncMiddleware, disableRobots, embedCSP } from '../middlewares'
14 14
15const clientsRouter = express.Router() 15const clientsRouter = express.Router()
16 16
@@ -81,6 +81,12 @@ clientsRouter.use('/client/*', (req: express.Request, res: express.Response) =>
81 res.status(HttpStatusCode.NOT_FOUND_404).end() 81 res.status(HttpStatusCode.NOT_FOUND_404).end()
82}) 82})
83 83
84// No index exceptions
85clientsRouter.all('/about/peertube',
86 disableRobots,
87 asyncMiddleware(serveIndexHTML)
88)
89
84// Always serve index client page (the client is a single page application, let it handle routing) 90// Always serve index client page (the client is a single page application, let it handle routing)
85// Try to provide the right language index.html 91// Try to provide the right language index.html
86clientsRouter.use('/(:language)?', asyncMiddleware(serveIndexHTML)) 92clientsRouter.use('/(:language)?', asyncMiddleware(serveIndexHTML))
diff --git a/server/controllers/static.ts b/server/controllers/static.ts
index 1c04e4b11..fe1629910 100644
--- a/server/controllers/static.ts
+++ b/server/controllers/static.ts
@@ -69,6 +69,7 @@ staticRouter.get('/robots.txt',
69 cacheRoute(ROUTE_CACHE_LIFETIME.ROBOTS), 69 cacheRoute(ROUTE_CACHE_LIFETIME.ROBOTS),
70 (_, res: express.Response) => { 70 (_, res: express.Response) => {
71 res.type('text/plain') 71 res.type('text/plain')
72
72 return res.send(CONFIG.INSTANCE.ROBOTS) 73 return res.send(CONFIG.INSTANCE.ROBOTS)
73 } 74 }
74) 75)
diff --git a/server/middlewares/index.ts b/server/middlewares/index.ts
index a0035f623..d2ed079b6 100644
--- a/server/middlewares/index.ts
+++ b/server/middlewares/index.ts
@@ -4,6 +4,7 @@ export * from './activitypub'
4export * from './async' 4export * from './async'
5export * from './auth' 5export * from './auth'
6export * from './pagination' 6export * from './pagination'
7export * from './robots'
7export * from './servers' 8export * from './servers'
8export * from './sort' 9export * from './sort'
9export * from './user-right' 10export * from './user-right'
diff --git a/server/middlewares/robots.ts b/server/middlewares/robots.ts
new file mode 100644
index 000000000..b22b24a9f
--- /dev/null
+++ b/server/middlewares/robots.ts
@@ -0,0 +1,13 @@
1import express from 'express'
2
3function disableRobots (req: express.Request, res: express.Response, next: express.NextFunction) {
4 res.setHeader('X-Robots-Tag', 'noindex')
5
6 return next()
7}
8
9// ---------------------------------------------------------------------------
10
11export {
12 disableRobots
13}
diff --git a/server/tests/client.ts b/server/tests/client.ts
index a91bec906..6c32c81db 100644
--- a/server/tests/client.ts
+++ b/server/tests/client.ts
@@ -482,6 +482,16 @@ describe('Test a client controllers', function () {
482 } 482 }
483 } 483 }
484 }) 484 })
485
486 it('Should add noindex header for some paths', async function () {
487 const paths = [ '/about/peertube' ]
488
489 for (const path of paths) {
490 const { headers } = await makeHTMLRequest(servers[0].url, path)
491
492 expect(headers['x-robots-tag']).to.equal('noindex')
493 }
494 })
485 }) 495 })
486 496
487 describe('Embed HTML', function () { 497 describe('Embed HTML', function () {