Angular Service Worker disabled in nginx

Viewed 32

I am building a Angular14 Progressive Web App (PWA) with service worker by following these guide.

The ServiceWorkerModule is importet in app.module.ts with this code:

ServiceWorkerModule.register('ngsw-worker.js', {
    enabled: true,
    registrationStrategy: 'registerWhenStable:30000'
})

If I hoste my Angular application with:

ng build
http-server -p 8080 -c-1 dist/dw-frontend

in chrome i can see that service workers are active and running (by chrome dev tools > App > Service Workers).

If I hoste the same application in a Docker container with nginx, it seems that the service workers are disabled. I can't figure out why they are activated in the first case and not with the same code in the second case.

Her is my nginx configuration file:

events{}
http {
    include /etc/nginx/mime.types;
    server {
        listen 80;
        server_name localhost;
        root /usr/share/nginx/html;
        index index.html;

        location / {
            try_files $uri $uri/ /index.html;
        }
    }
}
0 Answers
Related