aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/client.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/client.ts')
-rw-r--r--server/controllers/client.ts51
1 files changed, 40 insertions, 11 deletions
diff --git a/server/controllers/client.ts b/server/controllers/client.ts
index a85c10720..2d0c49904 100644
--- a/server/controllers/client.ts
+++ b/server/controllers/client.ts
@@ -5,27 +5,53 @@ 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 { root } from '@shared/core-utils'
8import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '@shared/core-utils/i18n' 9import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '@shared/core-utils/i18n'
9import { HttpStatusCode } from '@shared/models' 10import { HttpStatusCode } from '@shared/models'
10import { root } from '@shared/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, buildRateLimiter, embedCSP } from '../middlewares'
14 14
15const clientsRouter = express.Router() 15const clientsRouter = express.Router()
16 16
17const clientsRateLimiter = buildRateLimiter({
18 windowMs: CONFIG.RATES_LIMIT.CLIENT.WINDOW_MS,
19 max: CONFIG.RATES_LIMIT.CLIENT.MAX
20})
21
17const distPath = join(root(), 'client', 'dist') 22const distPath = join(root(), 'client', 'dist')
18const testEmbedPath = join(distPath, 'standalone', 'videos', 'test-embed.html') 23const testEmbedPath = join(distPath, 'standalone', 'videos', 'test-embed.html')
19 24
20// Special route that add OpenGraph and oEmbed tags 25// Special route that add OpenGraph and oEmbed tags
21// Do not use a template engine for a so little thing 26// Do not use a template engine for a so little thing
22clientsRouter.use([ '/w/p/:id', '/videos/watch/playlist/:id' ], asyncMiddleware(generateWatchPlaylistHtmlPage)) 27clientsRouter.use([ '/w/p/:id', '/videos/watch/playlist/:id' ],
23clientsRouter.use([ '/w/:id', '/videos/watch/:id' ], asyncMiddleware(generateWatchHtmlPage)) 28 clientsRateLimiter,
24clientsRouter.use([ '/accounts/:nameWithHost', '/a/:nameWithHost' ], asyncMiddleware(generateAccountHtmlPage)) 29 asyncMiddleware(generateWatchPlaylistHtmlPage)
25clientsRouter.use([ '/video-channels/:nameWithHost', '/c/:nameWithHost' ], asyncMiddleware(generateVideoChannelHtmlPage)) 30)
26clientsRouter.use('/@:nameWithHost', asyncMiddleware(generateActorHtmlPage)) 31
32clientsRouter.use([ '/w/:id', '/videos/watch/:id' ],
33 clientsRateLimiter,
34 asyncMiddleware(generateWatchHtmlPage)
35)
36
37clientsRouter.use([ '/accounts/:nameWithHost', '/a/:nameWithHost' ],
38 clientsRateLimiter,
39 asyncMiddleware(generateAccountHtmlPage)
40)
41
42clientsRouter.use([ '/video-channels/:nameWithHost', '/c/:nameWithHost' ],
43 clientsRateLimiter,
44 asyncMiddleware(generateVideoChannelHtmlPage)
45)
46
47clientsRouter.use('/@:nameWithHost',
48 clientsRateLimiter,
49 asyncMiddleware(generateActorHtmlPage)
50)
27 51
28const embedMiddlewares = [ 52const embedMiddlewares = [
53 clientsRateLimiter,
54
29 CONFIG.CSP.ENABLED 55 CONFIG.CSP.ENABLED
30 ? embedCSP 56 ? embedCSP
31 : (req: express.Request, res: express.Response, next: express.NextFunction) => next(), 57 : (req: express.Request, res: express.Response, next: express.NextFunction) => next(),
@@ -48,11 +74,11 @@ clientsRouter.use('/video-playlists/embed', ...embedMiddlewares)
48 74
49const testEmbedController = (req: express.Request, res: express.Response) => res.sendFile(testEmbedPath) 75const testEmbedController = (req: express.Request, res: express.Response) => res.sendFile(testEmbedPath)
50 76
51clientsRouter.use('/videos/test-embed', testEmbedController) 77clientsRouter.use('/videos/test-embed', clientsRateLimiter, testEmbedController)
52clientsRouter.use('/video-playlists/test-embed', testEmbedController) 78clientsRouter.use('/video-playlists/test-embed', clientsRateLimiter, testEmbedController)
53 79
54// Dynamic PWA manifest 80// Dynamic PWA manifest
55clientsRouter.get('/manifest.webmanifest', asyncMiddleware(generateManifest)) 81clientsRouter.get('/manifest.webmanifest', clientsRateLimiter, asyncMiddleware(generateManifest))
56 82
57// Static client overrides 83// Static client overrides
58// Must be consistent with static client overrides redirections in /support/nginx/peertube 84// Must be consistent with static client overrides redirections in /support/nginx/peertube
@@ -88,7 +114,10 @@ clientsRouter.use('/client/*', (req: express.Request, res: express.Response) =>
88 114
89// Always serve index client page (the client is a single page application, let it handle routing) 115// Always serve index client page (the client is a single page application, let it handle routing)
90// Try to provide the right language index.html 116// Try to provide the right language index.html
91clientsRouter.use('/(:language)?', asyncMiddleware(serveIndexHTML)) 117clientsRouter.use('/(:language)?',
118 clientsRateLimiter,
119 asyncMiddleware(serveIndexHTML)
120)
92 121
93// --------------------------------------------------------------------------- 122// ---------------------------------------------------------------------------
94 123