aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/client.ts21
1 files changed, 4 insertions, 17 deletions
diff --git a/server/controllers/client.ts b/server/controllers/client.ts
index bd1f19f8c..7a279d8d5 100644
--- a/server/controllers/client.ts
+++ b/server/controllers/client.ts
@@ -1,9 +1,10 @@
1import * as express from 'express' 1import * as express from 'express'
2import { constants, promises as fs } from 'fs' 2import { constants, promises as fs } from 'fs'
3import { readFile } from 'fs-extra'
3import { join } from 'path' 4import { join } from 'path'
4import { CONFIG } from '@server/initializers/config' 5import { CONFIG } from '@server/initializers/config'
5import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '@shared/core-utils/i18n'
6import { HttpStatusCode } from '@shared/core-utils' 6import { HttpStatusCode } from '@shared/core-utils'
7import { buildFileLocale, getCompleteLocale, I18N_LOCALES, is18nLocale, LOCALE_FILES } from '@shared/core-utils/i18n'
7import { root } from '../helpers/core-utils' 8import { root } from '../helpers/core-utils'
8import { STATIC_MAX_AGE } from '../initializers/constants' 9import { STATIC_MAX_AGE } from '../initializers/constants'
9import { ClientHtml, sendHTML, serveIndexHTML } from '../lib/client-html' 10import { ClientHtml, sendHTML, serveIndexHTML } from '../lib/client-html'
@@ -46,22 +47,8 @@ const testEmbedController = (req: express.Request, res: express.Response) => res
46clientsRouter.use('/videos/test-embed', testEmbedController) 47clientsRouter.use('/videos/test-embed', testEmbedController)
47clientsRouter.use('/video-playlists/test-embed', testEmbedController) 48clientsRouter.use('/video-playlists/test-embed', testEmbedController)
48 49
49// Static HTML/CSS/JS client files
50const staticClientFiles = [
51 'ngsw-worker.js',
52 'ngsw.json'
53]
54
55for (const staticClientFile of staticClientFiles) {
56 const path = join(root(), 'client', 'dist', staticClientFile)
57
58 clientsRouter.get(`/${staticClientFile}`, (req: express.Request, res: express.Response) => {
59 res.sendFile(path, { maxAge: STATIC_MAX_AGE.SERVER })
60 })
61}
62
63// Dynamic PWA manifest 50// Dynamic PWA manifest
64clientsRouter.get('/manifest.webmanifest', asyncMiddleware(generateManifest)) 51clientsRouter.get(/\/client\/[^/]+\/manifest.webmanifest/, asyncMiddleware(generateManifest))
65 52
66// Static client overrides 53// Static client overrides
67// Must be consistent with static client overrides redirections in /support/nginx/peertube 54// Must be consistent with static client overrides redirections in /support/nginx/peertube
@@ -149,7 +136,7 @@ async function generateVideoChannelHtmlPage (req: express.Request, res: express.
149 136
150async function generateManifest (req: express.Request, res: express.Response) { 137async function generateManifest (req: express.Request, res: express.Response) {
151 const manifestPhysicalPath = join(root(), 'client', 'dist', 'manifest.webmanifest') 138 const manifestPhysicalPath = join(root(), 'client', 'dist', 'manifest.webmanifest')
152 const manifestJson = await fs.readFile(manifestPhysicalPath, 'utf8') 139 const manifestJson = await readFile(manifestPhysicalPath, 'utf8')
153 const manifest = JSON.parse(manifestJson) 140 const manifest = JSON.parse(manifestJson)
154 141
155 manifest.name = CONFIG.INSTANCE.NAME 142 manifest.name = CONFIG.INSTANCE.NAME