diff options
-rw-r--r-- | client/src/app/app.module.ts | 5 | ||||
-rw-r--r-- | client/src/main.ts | 5 | ||||
-rw-r--r-- | client/src/manifest.webmanifest | 8 | ||||
-rw-r--r-- | client/src/ngsw-config.json | 1 | ||||
-rwxr-xr-x | scripts/build/client.sh | 3 | ||||
-rw-r--r-- | server/controllers/client.ts | 21 |
6 files changed, 14 insertions, 29 deletions
diff --git a/client/src/app/app.module.ts b/client/src/app/app.module.ts index 98dec4244..f790a6848 100644 --- a/client/src/app/app.module.ts +++ b/client/src/app/app.module.ts | |||
@@ -1,7 +1,9 @@ | |||
1 | import 'focus-visible' | 1 | import 'focus-visible' |
2 | import { environment } from 'src/environments/environment' | ||
2 | import { APP_BASE_HREF, registerLocaleData } from '@angular/common' | 3 | import { APP_BASE_HREF, registerLocaleData } from '@angular/common' |
3 | import { NgModule } from '@angular/core' | 4 | import { NgModule } from '@angular/core' |
4 | import { BrowserModule } from '@angular/platform-browser' | 5 | import { BrowserModule } from '@angular/platform-browser' |
6 | import { ServiceWorkerModule } from '@angular/service-worker' | ||
5 | import { ServerService } from '@app/core' | 7 | import { ServerService } from '@app/core' |
6 | import localeOc from '@app/helpers/locales/oc' | 8 | import localeOc from '@app/helpers/locales/oc' |
7 | import { MetaLoader, MetaModule, MetaStaticLoader, PageTitlePositioning } from '@ngx-meta/core' | 9 | import { MetaLoader, MetaModule, MetaStaticLoader, PageTitlePositioning } from '@ngx-meta/core' |
@@ -11,7 +13,7 @@ import { CoreModule } from './core' | |||
11 | import { EmptyComponent } from './empty.component' | 13 | import { EmptyComponent } from './empty.component' |
12 | import { HeaderComponent, SearchTypeaheadComponent, SuggestionComponent } from './header' | 14 | import { HeaderComponent, SearchTypeaheadComponent, SuggestionComponent } from './header' |
13 | import { HighlightPipe } from './header/highlight.pipe' | 15 | import { HighlightPipe } from './header/highlight.pipe' |
14 | import { NotificationComponent, LanguageChooserComponent, MenuComponent } from './menu' | 16 | import { LanguageChooserComponent, MenuComponent, NotificationComponent } from './menu' |
15 | import { ConfirmComponent } from './modal/confirm.component' | 17 | import { ConfirmComponent } from './modal/confirm.component' |
16 | import { CustomModalComponent } from './modal/custom-modal.component' | 18 | import { CustomModalComponent } from './modal/custom-modal.component' |
17 | import { InstanceConfigWarningModalComponent } from './modal/instance-config-warning-modal.component' | 19 | import { InstanceConfigWarningModalComponent } from './modal/instance-config-warning-modal.component' |
@@ -49,6 +51,7 @@ registerLocaleData(localeOc, 'oc') | |||
49 | 51 | ||
50 | imports: [ | 52 | imports: [ |
51 | BrowserModule, | 53 | BrowserModule, |
54 | ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production }), | ||
52 | 55 | ||
53 | CoreModule, | 56 | CoreModule, |
54 | SharedMainModule, | 57 | SharedMainModule, |
diff --git a/client/src/main.ts b/client/src/main.ts index 99976a3f7..84c82203d 100644 --- a/client/src/main.ts +++ b/client/src/main.ts | |||
@@ -11,11 +11,6 @@ if (environment.production) { | |||
11 | const bootstrap = () => platformBrowserDynamic() | 11 | const bootstrap = () => platformBrowserDynamic() |
12 | .bootstrapModule(AppModule) | 12 | .bootstrapModule(AppModule) |
13 | .then(bootstrapModule => { | 13 | .then(bootstrapModule => { |
14 | if ('serviceWorker' in navigator && environment.production) { | ||
15 | navigator.serviceWorker.register('/ngsw-worker.js') | ||
16 | .catch(err => console.error('Cannot register service worker.', err)) | ||
17 | } | ||
18 | |||
19 | if (!environment.production) { | 14 | if (!environment.production) { |
20 | const applicationRef = bootstrapModule.injector.get(ApplicationRef) | 15 | const applicationRef = bootstrapModule.injector.get(ApplicationRef) |
21 | const componentRef = applicationRef.components[0] | 16 | const componentRef = applicationRef.components[0] |
diff --git a/client/src/manifest.webmanifest b/client/src/manifest.webmanifest index 851e098a8..6e62856cd 100644 --- a/client/src/manifest.webmanifest +++ b/client/src/manifest.webmanifest | |||
@@ -1,4 +1,7 @@ | |||
1 | { | 1 | { |
2 | "name": "PeerTube", | ||
3 | "short_name": "PeerTube", | ||
4 | "start_url": "/", | ||
2 | "background_color": "#fff", | 5 | "background_color": "#fff", |
3 | "theme_color": "#fff", | 6 | "theme_color": "#fff", |
4 | "description": "A federated video streaming platform using P2P", | 7 | "description": "A federated video streaming platform using P2P", |
@@ -40,8 +43,5 @@ | |||
40 | "sizes": "512x512", | 43 | "sizes": "512x512", |
41 | "type": "image/png" | 44 | "type": "image/png" |
42 | } | 45 | } |
43 | ], | 46 | ] |
44 | "name": "PeerTube", | ||
45 | "short_name": "PeerTube", | ||
46 | "start_url": "/" | ||
47 | } | 47 | } |
diff --git a/client/src/ngsw-config.json b/client/src/ngsw-config.json index d68db79d0..af7554c00 100644 --- a/client/src/ngsw-config.json +++ b/client/src/ngsw-config.json | |||
@@ -1,4 +1,5 @@ | |||
1 | { | 1 | { |
2 | "$schema": "../node_modules/@angular/service-worker/config/schema.json", | ||
2 | "index": "/index.html", | 3 | "index": "/index.html", |
3 | "assetGroups": [ | 4 | "assetGroups": [ |
4 | { | 5 | { |
diff --git a/scripts/build/client.sh b/scripts/build/client.sh index e6f14a4e2..0e7925be5 100755 --- a/scripts/build/client.sh +++ b/scripts/build/client.sh | |||
@@ -69,8 +69,7 @@ else | |||
69 | npm run ng build -- --localize=false --output-path "dist/$defaultLanguage/" --deploy-url "/client/$defaultLanguage/" --prod --stats-json $additionalParams | 69 | npm run ng build -- --localize=false --output-path "dist/$defaultLanguage/" --deploy-url "/client/$defaultLanguage/" --prod --stats-json $additionalParams |
70 | fi | 70 | fi |
71 | 71 | ||
72 | mv "./dist/$defaultLanguage/manifest.webmanifest" "./dist/manifest.webmanifest" | 72 | cp "./dist/$defaultLanguage/manifest.webmanifest" "./dist/manifest.webmanifest" |
73 | mv "./dist/$defaultLanguage/ngsw-worker.js" "./dist/" | ||
74 | 73 | ||
75 | cd ../ && npm run build:embed && cd client/ | 74 | cd ../ && npm run build:embed && cd client/ |
76 | 75 | ||
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 |