diff options
Diffstat (limited to 'server/controllers/client.ts')
-rw-r--r-- | server/controllers/client.ts | 16 |
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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { join } from 'path' | 2 | import { join } from 'path' |
3 | import { root } from '../helpers/core-utils' | 3 | import { root } from '../helpers/core-utils' |
4 | import { ACCEPT_HEADERS, STATIC_MAX_AGE } from '../initializers/constants' | 4 | import { ACCEPT_HEADERS, STATIC_MAX_AGE, STATIC_PATHS } from '../initializers/constants' |
5 | import { asyncMiddleware, embedCSP } from '../middlewares' | 5 | import { asyncMiddleware, embedCSP } from '../middlewares' |
6 | import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '../../shared/models/i18n/i18n' | 6 | import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '../../shared/models/i18n/i18n' |
7 | import { ClientHtml } from '../lib/client-html' | 7 | import { ClientHtml } from '../lib/client-html' |
@@ -10,7 +10,6 @@ import { logger } from '../helpers/logger' | |||
10 | const clientsRouter = express.Router() | 10 | const clientsRouter = express.Router() |
11 | 11 | ||
12 | const distPath = join(root(), 'client', 'dist') | 12 | const distPath = join(root(), 'client', 'dist') |
13 | const assetsImagesPath = join(root(), 'client', 'dist', 'assets', 'images') | ||
14 | const embedPath = join(distPath, 'standalone', 'videos', 'embed.html') | 13 | const embedPath = join(distPath, 'standalone', 'videos', 'embed.html') |
15 | const testEmbedPath = join(distPath, 'standalone', 'videos', 'test-embed.html') | 14 | const testEmbedPath = join(distPath, 'standalone', 'videos', 'test-embed.html') |
16 | 15 | ||
@@ -42,13 +41,14 @@ const staticClientFiles = [ | |||
42 | ] | 41 | ] |
43 | for (const staticClientFile of staticClientFiles) { | 42 | for (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 | ||
48 | clientsRouter.use('/client', express.static(distPath, { maxAge: STATIC_MAX_AGE })) | 45 | clientsRouter.get('/' + staticClientFile, (req: express.Request, res: express.Response) => { |
49 | clientsRouter.use('/client/assets/images', express.static(assetsImagesPath, { maxAge: STATIC_MAX_AGE })) | 46 | res.sendFile(path, { maxAge: STATIC_MAX_AGE.SERVER }) |
47 | }) | ||
48 | } | ||
50 | 49 | ||
51 | clientsRouter.use('/client/locales/:locale/:file.json', serveServerTranslations) | 50 | clientsRouter.use('/client/locales/:locale/:file.json', serveServerTranslations) |
51 | clientsRouter.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 |
54 | clientsRouter.use('/client/*', (req: express.Request, res: express.Response) => { | 54 | clientsRouter.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) |