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.ts16
1 files changed, 9 insertions, 7 deletions
diff --git a/server/controllers/client.ts b/server/controllers/client.ts
index 18b8b58e9..51f610afa 100644
--- a/server/controllers/client.ts
+++ b/server/controllers/client.ts
@@ -1,7 +1,7 @@
1import * as express from 'express' 1import * as express from 'express'
2import { join } from 'path' 2import { join } from 'path'
3import { root } from '../helpers/core-utils' 3import { root } from '../helpers/core-utils'
4import { ACCEPT_HEADERS, STATIC_MAX_AGE } from '../initializers/constants' 4import { ACCEPT_HEADERS, STATIC_MAX_AGE, STATIC_PATHS } from '../initializers/constants'
5import { asyncMiddleware, embedCSP } from '../middlewares' 5import { asyncMiddleware, embedCSP } from '../middlewares'
6import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '../../shared/models/i18n/i18n' 6import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '../../shared/models/i18n/i18n'
7import { ClientHtml } from '../lib/client-html' 7import { ClientHtml } from '../lib/client-html'
@@ -10,7 +10,6 @@ import { logger } from '../helpers/logger'
10const clientsRouter = express.Router() 10const clientsRouter = express.Router()
11 11
12const distPath = join(root(), 'client', 'dist') 12const distPath = join(root(), 'client', 'dist')
13const assetsImagesPath = join(root(), 'client', 'dist', 'assets', 'images')
14const embedPath = join(distPath, 'standalone', 'videos', 'embed.html') 13const embedPath = join(distPath, 'standalone', 'videos', 'embed.html')
15const testEmbedPath = join(distPath, 'standalone', 'videos', 'test-embed.html') 14const testEmbedPath = join(distPath, 'standalone', 'videos', 'test-embed.html')
16 15
@@ -42,13 +41,14 @@ const staticClientFiles = [
42] 41]
43for (const staticClientFile of staticClientFiles) { 42for (const staticClientFile of staticClientFiles) {
44 const path = join(root(), 'client', 'dist', staticClientFile) 43 const path = join(root(), 'client', 'dist', staticClientFile)
45 clientsRouter.use('/' + staticClientFile, express.static(path, { maxAge: STATIC_MAX_AGE }))
46}
47 44
48clientsRouter.use('/client', express.static(distPath, { maxAge: STATIC_MAX_AGE })) 45 clientsRouter.get('/' + staticClientFile, (req: express.Request, res: express.Response) => {
49clientsRouter.use('/client/assets/images', express.static(assetsImagesPath, { maxAge: STATIC_MAX_AGE })) 46 res.sendFile(path, { maxAge: STATIC_MAX_AGE.SERVER })
47 })
48}
50 49
51clientsRouter.use('/client/locales/:locale/:file.json', serveServerTranslations) 50clientsRouter.use('/client/locales/:locale/:file.json', serveServerTranslations)
51clientsRouter.use('/client', express.static(distPath, { maxAge: STATIC_MAX_AGE.CLIENT }))
52 52
53// 404 for static files not found 53// 404 for static files not found
54clientsRouter.use('/client/*', (req: express.Request, res: express.Response) => { 54clientsRouter.use('/client/*', (req: express.Request, res: express.Response) => {
@@ -74,7 +74,9 @@ async function serveServerTranslations (req: express.Request, res: express.Respo
74 if (is18nLocale(locale) && LOCALE_FILES.indexOf(file) !== -1) { 74 if (is18nLocale(locale) && LOCALE_FILES.indexOf(file) !== -1) {
75 const completeLocale = getCompleteLocale(locale) 75 const completeLocale = getCompleteLocale(locale)
76 const completeFileLocale = buildFileLocale(completeLocale) 76 const completeFileLocale = buildFileLocale(completeLocale)
77 return res.sendFile(join(__dirname, `../../../client/dist/locale/${file}_${completeFileLocale}.json`)) 77
78 const path = join(__dirname, `../../../client/dist/locale/${file}_${completeFileLocale}.json`)
79 return res.sendFile(path, { maxAge: STATIC_MAX_AGE.SERVER })
78 } 80 }
79 81
80 return res.sendStatus(404) 82 return res.sendStatus(404)