Сервисный работник не работает в Angular 8 - PullRequest
0 голосов
/ 21 июня 2019

Задача

http://localhost:8080/

 Unhandled requests will be served from: http://localhost:8080
 Hit CTRL-C to stop the server
 [2019-06-21T06:37:57.110Z] "GET /" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.

Добавление работника службы

   ng add @angular/pwa --project *project-name*

Проект здания

 ng build --prod

Обслуживание с http-сервером

http-сервер -p 8080 -c-1 dist /

   PS D:\angular-tour-of-heroes> http-server -p 8080 -c-1 dist/angular-tour-of-heroes
             http://localhost:8080
            Starting up http-server, serving ./
            Available on:
              http://192.168.0.179:8080
              http://127.0.0.1:8080
            Unhandled requests will be served from:  http://localhost:8080
            Hit CTRL-C to stop the server
            [2019-06-21T06:37:57.110Z] "GET /" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"
            (node:3348) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
            [2019-06-21T06:38:09.511Z] "GET /" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"
            [2019-06-21T06:38:09.653Z] "GET /" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"
            [2019-06-21T06:38:14.680Z] "GET /" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"
            [2019-06-21T07:17:49.186Z] "GET /" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"
            [2019-06-21T07:17:49.249Z] "GET /" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"
            [2019-06-21T07:17:54.683Z] "GET /" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"
            [2019-06-21T07:17:54.775Z] "GET /" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"

index.html

<link rel="manifest" href="manifest.webmanifest">

manifest.webmanifest

            {
              "name": "angular-tour-of-heroes",
              "short_name": "angular-tour-of-heroes",
              "theme_color": "#1976d2",
              "background_color": "#fafafa",
              "display": "standalone",
              "scope": "/",
              "start_url": "http://localhost:8080/",
              "icons": [
                {
                  "src": "assets/icons/icon-72x72.png",
                  "sizes": "72x72",
                  "type": "image/png"
                },

              ]
            }

обновленный манифест

        {
          "name": "angular-tour-of-heroes",
          "short_name": "angular-tour-of-heroes",
          "theme_color": "#1976d2",
          "background_color": "#fafafa",
          "display": "standalone",
          "scope": "/",
          "start_url": "/",
          "icons": [

Пробовал запустить снова

        PS D:\angular-tour-of-heroes> http-server -p 8080 -c-1 dist/angular-tour-of-heroes
            Starting up http-server, serving dist/angular-tour-of-heroes
            Available on:
            http://192.168.0.179:8080
            http://127.0.0.1:8080
            Hit CTRL-C to stop the server
            [2019-06-27T05:30:36.720Z] "GET /" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36"
            (node:3160) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
            [2019-06-27T05:30:36.727Z] "GET /" Error (404): "Not found"

Уже установлен

  npm install http-server -g

https://www.npmjs.com/package/http-server

ng verison

            Angular CLI: 8.0.3
            Node: 12.4.0
            OS: win32 x64
            Angular: 8.0.1
            ... animations, cdk, common, compiler, compiler-cli, core, forms
            ... language-service, material, platform-browser
            ... platform-browser-dynamic, router, service-worker

            Package                           Version
            -----------------------------------------------------------
            @angular-devkit/architect         0.800.3
            @angular-devkit/build-angular     0.800.3
            @angular-devkit/build-optimizer   0.800.3
            @angular-devkit/build-webpack     0.800.3
            @angular-devkit/core              8.0.3
            @angular-devkit/schematics        8.0.3
            @angular/cli                      8.0.3
            @angular/http                     7.2.15
            @angular/pwa                      0.800.3
            @ngtools/webpack                  8.0.3
            @schematics/angular               8.0.3
            @schematics/update                0.800.3 (cli-only)
            rxjs                              6.5.2
            typescript                        3.4.5
            webpack                           4.30.0

Angular.json

         "configurations": {
                "production": {
                  "optimization": true,
                  "outputHashing": "all",
                  "sourceMap": false,
                  "extractCss": true,
                  "namedChunks": false,
                  "aot": true,
                  "extractLicenses": true,
                  "vendorChunk": false,
                  "buildOptimizer": true,
                  "fileReplacements": [
                    {
                      "replace": "src/environments/environment.ts",
                      "with": "src/environments/environment.prod.ts"
                    }
                  ],
                  "serviceWorker": true,
                  "ngswConfigPath": "ngsw-config.json"
                }

Package.json

     "dependencies": {
        "@angular/animations": "8.0.1",
        "@angular/cdk": "~8.0.1",
        "@angular/common": "8.0.1",
        "@angular/compiler": "8.0.1",
        "@angular/core": "8.0.1",
        "@angular/forms": "8.0.1",
        "@angular/http": "7.2.15",
        "@angular/material": "^8.0.1",
        "@angular/platform-browser": "8.0.1",
        "@angular/platform-browser-dynamic": "8.0.1",
        "@angular/pwa": "^0.800.3",
        "@angular/router": "8.0.1",
        "@angular/service-worker": "8.0.1",

main.ts

от

platformBrowserDynamic().bootstrapModule(AppModule);

до

 platformBrowserDynamic().bootstrapModule(AppModule).then(() => {
 if ('serviceWorker' in navigator && environment.production) {
  navigator.serviceWorker.register('/ngsw-worker.js');
 }
}).catch(err => console.log(err));
  • я остановил http://localhost:4200/, чтобы служба http могла работать.

  • я не могу понять, почему localhost: 8080 не работает

enter image description here

...