X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fclient.ts;h=08c0f1fa61b40958a01538086104abf30cfcdbed;hb=399b3bc9a638482e93de27a99a372b45fc3ece43;hp=18b8b58e9ca5db62efb89e38c2c598ff9afa5d48;hpb=552d95b1e69fbbd99f5bc300a127457e1b97b9df;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/client.ts b/server/controllers/client.ts index 18b8b58e9..08c0f1fa6 100644 --- a/server/controllers/client.ts +++ b/server/controllers/client.ts @@ -6,11 +6,11 @@ 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() const distPath = join(root(), 'client', 'dist') -const assetsImagesPath = join(root(), 'client', 'dist', 'assets', 'images') const embedPath = join(distPath, 'standalone', 'videos', 'embed.html') const testEmbedPath = join(distPath, 'standalone', 'videos', 'test-embed.html') @@ -20,9 +20,13 @@ 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', - embedCSP, + embedCSPMiddleware, (req: express.Request, res: express.Response) => { res.removeHeader('X-Frame-Options') res.sendFile(embedPath) @@ -42,13 +46,14 @@ const staticClientFiles = [ ] for (const staticClientFile of staticClientFiles) { const path = join(root(), 'client', 'dist', staticClientFile) - clientsRouter.use('/' + staticClientFile, express.static(path, { maxAge: STATIC_MAX_AGE })) -} -clientsRouter.use('/client', express.static(distPath, { maxAge: STATIC_MAX_AGE })) -clientsRouter.use('/client/assets/images', express.static(assetsImagesPath, { maxAge: STATIC_MAX_AGE })) + clientsRouter.get('/' + staticClientFile, (req: express.Request, res: express.Response) => { + res.sendFile(path, { maxAge: STATIC_MAX_AGE.SERVER }) + }) +} clientsRouter.use('/client/locales/:locale/:file.json', serveServerTranslations) +clientsRouter.use('/client', express.static(distPath, { maxAge: STATIC_MAX_AGE.CLIENT })) // 404 for static files not found clientsRouter.use('/client/*', (req: express.Request, res: express.Response) => { @@ -67,14 +72,16 @@ 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) - return res.sendFile(join(__dirname, `../../../client/dist/locale/${file}_${completeFileLocale}.json`)) + + const path = join(__dirname, `../../../client/dist/locale/${file}.${completeFileLocale}.json`) + return res.sendFile(path, { maxAge: STATIC_MAX_AGE.SERVER }) } return res.sendStatus(404)