diff options
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/client.ts | 16 | ||||
-rw-r--r-- | server/controllers/static.ts | 4 |
2 files changed, 11 insertions, 9 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) |
diff --git a/server/controllers/static.ts b/server/controllers/static.ts index af7de562a..4296183a0 100644 --- a/server/controllers/static.ts +++ b/server/controllers/static.ts | |||
@@ -68,13 +68,13 @@ staticRouter.use( | |||
68 | const thumbnailsPhysicalPath = CONFIG.STORAGE.THUMBNAILS_DIR | 68 | const thumbnailsPhysicalPath = CONFIG.STORAGE.THUMBNAILS_DIR |
69 | staticRouter.use( | 69 | staticRouter.use( |
70 | STATIC_PATHS.THUMBNAILS, | 70 | STATIC_PATHS.THUMBNAILS, |
71 | express.static(thumbnailsPhysicalPath, { maxAge: STATIC_MAX_AGE, fallthrough: false }) // 404 if the file does not exist | 71 | express.static(thumbnailsPhysicalPath, { maxAge: STATIC_MAX_AGE.SERVER, fallthrough: false }) // 404 if the file does not exist |
72 | ) | 72 | ) |
73 | 73 | ||
74 | const avatarsPhysicalPath = CONFIG.STORAGE.AVATARS_DIR | 74 | const avatarsPhysicalPath = CONFIG.STORAGE.AVATARS_DIR |
75 | staticRouter.use( | 75 | staticRouter.use( |
76 | STATIC_PATHS.AVATARS, | 76 | STATIC_PATHS.AVATARS, |
77 | express.static(avatarsPhysicalPath, { maxAge: STATIC_MAX_AGE, fallthrough: false }) // 404 if the file does not exist | 77 | express.static(avatarsPhysicalPath, { maxAge: STATIC_MAX_AGE.SERVER, fallthrough: false }) // 404 if the file does not exist |
78 | ) | 78 | ) |
79 | 79 | ||
80 | // We don't have video previews, fetch them from the origin instance | 80 | // We don't have video previews, fetch them from the origin instance |