]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/client.ts
Fix video view filename
[github/Chocobozzz/PeerTube.git] / server / controllers / client.ts
index dc3ff18fc7e6f1cd8b7a721eff48776f696977c5..65b5a053c9f4004eabe78687feb80c82e79bb412 100644 (file)
@@ -2,10 +2,11 @@ import * as express from 'express'
 import { join } from 'path'
 import { root } from '../helpers/core-utils'
 import { ACCEPT_HEADERS, STATIC_MAX_AGE } from '../initializers/constants'
-import { asyncMiddleware } from '../middlewares'
+import { asyncMiddleware, embedCSP } from '../middlewares'
 import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '../../shared/models/i18n/i18n'
 import { ClientHtml } from '../lib/client-html'
 import { logger } from '../helpers/logger'
+import { CONFIG } from '@server/initializers/config'
 
 const clientsRouter = express.Router()
 
@@ -19,11 +20,17 @@ clientsRouter.use('/videos/watch/:id', asyncMiddleware(generateWatchHtmlPage))
 clientsRouter.use('/accounts/:nameWithHost', asyncMiddleware(generateAccountHtmlPage))
 clientsRouter.use('/video-channels/:nameWithHost', asyncMiddleware(generateVideoChannelHtmlPage))
 
+const embedCSPMiddleware = CONFIG.CSP.ENABLED
+  ? embedCSP
+  : (req: express.Request, res: express.Response, next: express.NextFunction) => next()
+
 clientsRouter.use(
   '/videos/embed',
+  embedCSPMiddleware,
   (req: express.Request, res: express.Response) => {
     res.removeHeader('X-Frame-Options')
-    res.sendFile(embedPath)
+    // Don't cache HTML file since it's an index to the immutable JS/CSS files
+    res.sendFile(embedPath, { maxAge: 0 })
   }
 )
 clientsRouter.use(
@@ -66,11 +73,11 @@ export {
 
 // ---------------------------------------------------------------------------
 
-async function serveServerTranslations (req: express.Request, res: express.Response) {
+function serveServerTranslations (req: express.Request, res: express.Response) {
   const locale = req.params.locale
   const file = req.params.file
 
-  if (is18nLocale(locale) && LOCALE_FILES.indexOf(file) !== -1) {
+  if (is18nLocale(locale) && LOCALE_FILES.includes(file)) {
     const completeLocale = getCompleteLocale(locale)
     const completeFileLocale = buildFileLocale(completeLocale)