diff options
author | Chocobozzz <me@florianbigard.com> | 2021-01-18 11:16:37 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-01-18 11:16:37 +0100 |
commit | 1d22d2514f7be14d51ed2ab78e13df5da2646546 (patch) | |
tree | 87ee5fde348f9b648efeff82461867ee2d1c0fb2 /server | |
parent | 83befebe52139f7533669b2e9b99ca1f807eb7ce (diff) | |
download | PeerTube-1d22d2514f7be14d51ed2ab78e13df5da2646546.tar.gz PeerTube-1d22d2514f7be14d51ed2ab78e13df5da2646546.tar.zst PeerTube-1d22d2514f7be14d51ed2ab78e13df5da2646546.zip |
Fix service worker
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/client.ts | 21 |
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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { constants, promises as fs } from 'fs' | 2 | import { constants, promises as fs } from 'fs' |
3 | import { readFile } from 'fs-extra' | ||
3 | import { join } from 'path' | 4 | import { join } from 'path' |
4 | import { CONFIG } from '@server/initializers/config' | 5 | import { CONFIG } from '@server/initializers/config' |
5 | import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '@shared/core-utils/i18n' | ||
6 | import { HttpStatusCode } from '@shared/core-utils' | 6 | import { HttpStatusCode } from '@shared/core-utils' |
7 | import { buildFileLocale, getCompleteLocale, I18N_LOCALES, is18nLocale, LOCALE_FILES } from '@shared/core-utils/i18n' | ||
7 | import { root } from '../helpers/core-utils' | 8 | import { root } from '../helpers/core-utils' |
8 | import { STATIC_MAX_AGE } from '../initializers/constants' | 9 | import { STATIC_MAX_AGE } from '../initializers/constants' |
9 | import { ClientHtml, sendHTML, serveIndexHTML } from '../lib/client-html' | 10 | import { ClientHtml, sendHTML, serveIndexHTML } from '../lib/client-html' |
@@ -46,22 +47,8 @@ const testEmbedController = (req: express.Request, res: express.Response) => res | |||
46 | clientsRouter.use('/videos/test-embed', testEmbedController) | 47 | clientsRouter.use('/videos/test-embed', testEmbedController) |
47 | clientsRouter.use('/video-playlists/test-embed', testEmbedController) | 48 | clientsRouter.use('/video-playlists/test-embed', testEmbedController) |
48 | 49 | ||
49 | // Static HTML/CSS/JS client files | ||
50 | const staticClientFiles = [ | ||
51 | 'ngsw-worker.js', | ||
52 | 'ngsw.json' | ||
53 | ] | ||
54 | |||
55 | for (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 |
64 | clientsRouter.get('/manifest.webmanifest', asyncMiddleware(generateManifest)) | 51 | clientsRouter.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 | ||
150 | async function generateManifest (req: express.Request, res: express.Response) { | 137 | async 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 |