2

I am running http-server -c-1 to serve a simple http server to test my angular PWA app. However each time I visit localhost:8080 i get the Index of/ page. My manifest.json is configured for "start_url": "http://localhost:8080/" just like in the angular tutorial documents. https://blog.angular-university.io/angular-service-worker/

I have tried changing the manifest.json "start_url": "index.html" and to "start_url": "/" same results. Any ideas or suggestions why this is happening?

O.MeeKoh
  • 1,976
  • 3
  • 24
  • 53
  • For tutorials, please refer to the [official doc](https://angular.io/guide/service-worker-intro). Nowadays the setup is as simple as `ng add @angular/pwa --project *project-name*` – Ploppy Oct 03 '18 at 11:13
  • Since your index file is at the root, it should be `"start_url": "/"`. If your server does not redirect the users to the index.html, you have to load `localhost:8080/index.html` to test it properly. – Ploppy Oct 03 '18 at 11:14
  • yes I have done that. I am able to get it working when i do ng build --prod and then start the http-server however locally in dev I cannot get it to work. – O.MeeKoh Oct 03 '18 at 11:14
  • I edited my previous comment, please check it again. – Ploppy Oct 03 '18 at 11:15
  • @Ploppy yes, as I mentioned I had tried that and I am getting index of. When i run ng serve, everything works correctly – O.MeeKoh Oct 03 '18 at 11:15
  • 1
    The service worker is not working in dev mode, if you want to test it, you have to build your app with `ng build --prod` and then start the http-server on the `/dist/*project-name*` folder. – Ploppy Oct 03 '18 at 11:17
  • The Service worker doesn't work in Dev mode,as you register it in your app module for production mode only. For example `environment.production ? ServiceWorkerModule.register('ngsw-worker.js') : []`. Hence you need to build your app for production and host it on your server. – Sarthak Aggarwal Oct 03 '18 at 12:02
  • Yes, so the issue was that I was not running the http-server with production build. Once I ran production build I could still access everything just fine using localhost:8080 – O.MeeKoh Oct 03 '18 at 12:06
  • Possible duplicate of https://stackoverflow.com/questions/52535993/angular-6-angular-pwa-sw-does-not-successfuly-serve-the-manifests-start-url – Sahil Babbar Mar 09 '19 at 12:02

0 Answers0