Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Stop indexing /about/peertube

Chocobozzz655c957cc300
diff --git a/server/controllers/client.ts b/server/controllers/client.ts
index d81e35ec3d..cdc556da2b 100644
--- a/server/controllers/client.ts
+++ b/server/controllers/client.ts
@@ -5,12 +5,12 @@ import { join } from 'path'
import { logger } from '@server/helpers/logger'
import { CONFIG } from '@server/initializers/config'
import { Hooks } from '@server/lib/plugins/hooks'
-import { HttpStatusCode } from '@shared/models'
import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '@shared/core-utils/i18n'
+import { HttpStatusCode } from '@shared/models'
import { root } from '../helpers/core-utils'
import { STATIC_MAX_AGE } from '../initializers/constants'
import { ClientHtml, sendHTML, serveIndexHTML } from '../lib/client-html'
-import { asyncMiddleware, embedCSP } from '../middlewares'
+import { asyncMiddleware, disableRobots, embedCSP } from '../middlewares'
const clientsRouter = express.Router()
@@ -81,6 +81,12 @@ clientsRouter.use('/client/*', (req: express.Request, res: express.Response) =>
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)
// Try to provide the right language index.html
clientsRouter.use('/(:language)?', asyncMiddleware(serveIndexHTML))
diff --git a/server/controllers/static.ts b/server/controllers/static.ts
index 1c04e4b11e..fe16299107 100644
--- a/server/controllers/static.ts
+++ b/server/controllers/static.ts
@@ -69,6 +69,7 @@ staticRouter.get('/robots.txt',
cacheRoute(ROUTE_CACHE_LIFETIME.ROBOTS),
(_, res: express.Response) => {
res.type('text/plain')
+
return res.send(CONFIG.INSTANCE.ROBOTS)
}
)
diff --git a/server/middlewares/index.ts b/server/middlewares/index.ts
index a0035f623a..d2ed079b66 100644
--- a/server/middlewares/index.ts
+++ b/server/middlewares/index.ts
@@ -4,6 +4,7 @@ export * from './activitypub'
export * from './async'
export * from './auth'
export * from './pagination'
+export * from './robots'
export * from './servers'
export * from './sort'
export * from './user-right'
diff --git a/server/middlewares/robots.ts b/server/middlewares/robots.ts
new file mode 100644
index 0000000000..b22b24a9f8
--- /dev/null
+++ b/server/middlewares/robots.ts
@@ -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
+}
diff --git a/server/tests/client.ts b/server/tests/client.ts
index a91bec9068..6c32c81db8 100644
--- a/server/tests/client.ts
+++ b/server/tests/client.ts
@@ -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 () {