X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fclient.ts;h=335a0e082f2d6b570c6e026bd34ea911ba518672;hb=af4ae64f6faf38f8179f2e07d3cd4ad60006be92;hp=8c7f881a9eab9bdda600cccd11e0a92ab7e7ce51;hpb=8d987ec63e6888c839ad55938d45809869c517c6;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/client.ts b/server/controllers/client.ts index 8c7f881a9..335a0e082 100644 --- a/server/controllers/client.ts +++ b/server/controllers/client.ts @@ -1,18 +1,17 @@ -import { constants, promises as fs } from 'fs' import * as express from 'express' +import { constants, promises as fs } from 'fs' import { join } from 'path' +import { CONFIG } from '@server/initializers/config' +import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '@shared/core-utils/i18n' import { root } from '../helpers/core-utils' +import { logger } from '../helpers/logger' import { ACCEPT_HEADERS, STATIC_MAX_AGE } from '../initializers/constants' -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' +import { asyncMiddleware, embedCSP } from '../middlewares' const clientsRouter = express.Router() const distPath = join(root(), 'client', 'dist') -const embedPath = join(distPath, 'standalone', 'videos', 'embed.html') const testEmbedPath = join(distPath, 'standalone', 'videos', 'test-embed.html') // Special route that add OpenGraph and oEmbed tags @@ -22,23 +21,30 @@ 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() +const embedMiddlewares = [ + 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) => { + (req: express.Request, res: express.Response, next: express.NextFunction) => { res.removeHeader('X-Frame-Options') + // Don't cache HTML file since it's an index to the immutable JS/CSS files - res.sendFile(embedPath, { maxAge: 0 }) - } -) -clientsRouter.use( - '/videos/test-embed', - (req: express.Request, res: express.Response) => res.sendFile(testEmbedPath) -) + res.setHeader('Cache-Control', 'public, max-age=0') + + next() + }, + + asyncMiddleware(generateEmbedHtmlPage) +] + +clientsRouter.use('/videos/embed', ...embedMiddlewares) +clientsRouter.use('/video-playlists/embed', ...embedMiddlewares) + +const testEmbedController = (req: express.Request, res: express.Response) => res.sendFile(testEmbedPath) + +clientsRouter.use('/videos/test-embed', testEmbedController) +clientsRouter.use('/video-playlists/test-embed', testEmbedController) // Static HTML/CSS/JS client files const staticClientFiles = [ @@ -123,6 +129,12 @@ async function serveIndexHTML (req: express.Request, res: express.Response) { return res.status(404).end() } +async function generateEmbedHtmlPage (req: express.Request, res: express.Response) { + const html = await ClientHtml.getEmbedHTML() + + return sendHTML(html, res) +} + async function generateHTMLPage (req: express.Request, res: express.Response, paramLang?: string) { const html = await ClientHtml.getDefaultHTMLPage(req, res, paramLang)