aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-02-22 14:15:23 +0100
committerChocobozzz <me@florianbigard.com>2018-02-22 14:15:23 +0100
commit78967fca4cacbc247fa6fb62d64b2d6825a10804 (patch)
treef063a82b0658005e3d5ce23648333805782155ed
parent93df58cc4865af9046d2b31e03fa37d3ae54e45b (diff)
downloadPeerTube-78967fca4cacbc247fa6fb62d64b2d6825a10804.tar.gz
PeerTube-78967fca4cacbc247fa6fb62d64b2d6825a10804.tar.zst
PeerTube-78967fca4cacbc247fa6fb62d64b2d6825a10804.zip
Register service worker
-rw-r--r--CHANGELOG.md4
-rw-r--r--client/src/app/app.module.ts6
-rw-r--r--client/src/app/core/core.module.ts8
-rw-r--r--client/src/main.ts13
-rw-r--r--client/src/manifest.json2
-rw-r--r--server/controllers/client.ts15
6 files changed, 34 insertions, 14 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9fe96ea79..7f2e376cf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,10 @@
2 2
3## v0.0.27-alpha 3## v0.0.27-alpha
4 4
5### Features
6
7 * Add ability for admin to inject custom JavaScript/CSS
8
5### Bug fixes 9### Bug fixes
6 10
7 * Fix comment reply highlighting 11 * Fix comment reply highlighting
diff --git a/client/src/app/app.module.ts b/client/src/app/app.module.ts
index 34114b60b..cae99786b 100644
--- a/client/src/app/app.module.ts
+++ b/client/src/app/app.module.ts
@@ -1,11 +1,9 @@
1import { NgModule } from '@angular/core' 1import { NgModule } from '@angular/core'
2import { BrowserModule } from '@angular/platform-browser' 2import { BrowserModule } from '@angular/platform-browser'
3import { ServiceWorkerModule } from '@angular/service-worker'
4import { AboutModule } from '@app/about' 3import { AboutModule } from '@app/about'
5import { ResetPasswordModule } from '@app/reset-password' 4import { ResetPasswordModule } from '@app/reset-password'
6 5
7import { MetaLoader, MetaModule, MetaStaticLoader, PageTitlePositioning } from '@ngx-meta/core' 6import { MetaLoader, MetaModule, MetaStaticLoader, PageTitlePositioning } from '@ngx-meta/core'
8import { environment } from '../environments/environment'
9 7
10import { AccountModule } from './account' 8import { AccountModule } from './account'
11 9
@@ -60,9 +58,7 @@ export function metaFactory (): MetaLoader {
60 MetaModule.forRoot({ 58 MetaModule.forRoot({
61 provide: MetaLoader, 59 provide: MetaLoader,
62 useFactory: (metaFactory) 60 useFactory: (metaFactory)
63 }), 61 })
64
65 ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production })
66 ], 62 ],
67 providers: [ ] 63 providers: [ ]
68}) 64})
diff --git a/client/src/app/core/core.module.ts b/client/src/app/core/core.module.ts
index 93c9741a7..eea6f340b 100644
--- a/client/src/app/core/core.module.ts
+++ b/client/src/app/core/core.module.ts
@@ -1,7 +1,7 @@
1import { NgModule, Optional, SkipSelf } from '@angular/core'
2import { CommonModule } from '@angular/common' 1import { CommonModule } from '@angular/common'
3import { RouterModule } from '@angular/router' 2import { NgModule, Optional, SkipSelf } from '@angular/core'
4import { BrowserAnimationsModule } from '@angular/platform-browser/animations' 3import { BrowserAnimationsModule } from '@angular/platform-browser/animations'
4import { RouterModule } from '@angular/router'
5import { LoadingBarModule } from '@ngx-loading-bar/core' 5import { LoadingBarModule } from '@ngx-loading-bar/core'
6import { LoadingBarHttpClientModule } from '@ngx-loading-bar/http-client' 6import { LoadingBarHttpClientModule } from '@ngx-loading-bar/http-client'
7 7
@@ -9,10 +9,10 @@ import { SimpleNotificationsModule } from 'angular2-notifications'
9import { ModalModule } from 'ngx-bootstrap/modal' 9import { ModalModule } from 'ngx-bootstrap/modal'
10 10
11import { AuthService } from './auth' 11import { AuthService } from './auth'
12import { LoginGuard, UserRightGuard } from './routing'
13import { ServerService } from './server'
14import { ConfirmComponent, ConfirmService } from './confirm' 12import { ConfirmComponent, ConfirmService } from './confirm'
15import { throwIfAlreadyLoaded } from './module-import-guard' 13import { throwIfAlreadyLoaded } from './module-import-guard'
14import { LoginGuard, UserRightGuard } from './routing'
15import { ServerService } from './server'
16 16
17@NgModule({ 17@NgModule({
18 imports: [ 18 imports: [
diff --git a/client/src/main.ts b/client/src/main.ts
index b02b6830f..9686ba4b8 100644
--- a/client/src/main.ts
+++ b/client/src/main.ts
@@ -12,6 +12,19 @@ if (environment.production) {
12 12
13const bootstrap = () => platformBrowserDynamic() 13const bootstrap = () => platformBrowserDynamic()
14 .bootstrapModule(AppModule) 14 .bootstrapModule(AppModule)
15 .then(bootstrapModule => {
16 // TODO: Remove when https://github.com/angular/angular-cli/issues/8779 is fixed?
17 if ('serviceWorker' in navigator && environment.production) {
18 navigator.serviceWorker.register('/ngsw-worker.js')
19 .catch(err => console.error('Cannot register service worker.', err))
20 }
21
22 return bootstrapModule
23 })
24 .catch(err => {
25 console.error(err)
26 return null
27 })
15 28
16if (environment.hmr) { 29if (environment.hmr) {
17 if (module[ 'hot' ]) { 30 if (module[ 'hot' ]) {
diff --git a/client/src/manifest.json b/client/src/manifest.json
index 707efb973..30914e35f 100644
--- a/client/src/manifest.json
+++ b/client/src/manifest.json
@@ -43,5 +43,5 @@
43 ], 43 ],
44 "name": "PeerTube", 44 "name": "PeerTube",
45 "short_name": "PeerTube", 45 "short_name": "PeerTube",
46 "start_url": "." 46 "start_url": "/videos/trending"
47} 47}
diff --git a/server/controllers/client.ts b/server/controllers/client.ts
index f5124c55b..2fcca6f76 100644
--- a/server/controllers/client.ts
+++ b/server/controllers/client.ts
@@ -11,8 +11,6 @@ const clientsRouter = express.Router()
11 11
12const distPath = join(root(), 'client', 'dist') 12const distPath = join(root(), 'client', 'dist')
13const assetsImagesPath = join(root(), 'client', 'dist', 'client', 'assets', 'images') 13const assetsImagesPath = join(root(), 'client', 'dist', 'client', 'assets', 'images')
14const manifestPath = join(root(), 'client', 'dist', 'manifest.json')
15const serviceWorkerPath = join(root(), 'client', 'dist', 'ngsw-worker.js')
16const embedPath = join(distPath, 'standalone', 'videos', 'embed.html') 14const embedPath = join(distPath, 'standalone', 'videos', 'embed.html')
17const indexPath = join(distPath, 'index.html') 15const indexPath = join(distPath, 'index.html')
18 16
@@ -27,8 +25,17 @@ clientsRouter.use('/videos/embed', (req: express.Request, res: express.Response,
27}) 25})
28 26
29// Static HTML/CSS/JS client files 27// Static HTML/CSS/JS client files
30clientsRouter.use('/manifest.json', express.static(manifestPath, { maxAge: STATIC_MAX_AGE })) 28
31clientsRouter.use('/ngsw-worker.js', express.static(serviceWorkerPath, { maxAge: STATIC_MAX_AGE })) 29const staticClientFiles = [
30 'manifest.json',
31 'ngsw-worker.js',
32 'ngsw.json'
33]
34for (const staticClientFile of staticClientFiles) {
35 const path = join(root(), 'client', 'dist', staticClientFile)
36 clientsRouter.use('/' + staticClientFile, express.static(path, { maxAge: STATIC_MAX_AGE }))
37}
38
32clientsRouter.use('/client', express.static(distPath, { maxAge: STATIC_MAX_AGE })) 39clientsRouter.use('/client', express.static(distPath, { maxAge: STATIC_MAX_AGE }))
33clientsRouter.use('/client/assets/images', express.static(assetsImagesPath, { maxAge: STATIC_MAX_AGE })) 40clientsRouter.use('/client/assets/images', express.static(assetsImagesPath, { maxAge: STATIC_MAX_AGE }))
34 41