Angular Firebase service worker deploy in folder

380 views
Skip to first unread message

Juan Medina

unread,
Feb 8, 2019, 11:50:19 PM2/8/19
to Firebase Google Group
I use Firebase to send  push notifications to my Angular app.

I do it following this tutorial:


and all works ok when I try it in localhost.

The problem is when I deploy it because I do it in a folder, but the service worker is still search in the root and then is not found.

I deploy with this command:

ng build --prod --base-href /myfolder/

And then the service worker is in:


But the app still search for it in 


How can I say search it in myfolder?

I see some similar question here:


But I don't have this firebase.json... I suppouse is because is an Angular app.

Hope someone can help me.

Thanks in advance

Juan Medina

unread,
Feb 13, 2019, 10:52:51 AM2/13/19
to Firebase Google Group
I have already found the solution.

When the files are generated with npm run build

in one of the files with a name similar to '4.a514e2ef0845553d68e7.js' create this code

navigator.serviceWorker.register ("/ firebase-messaging-sw.js", {scope: "/ firebase-cloud-messaging-push-scope"})

with absolute path

when should I create

navigator.serviceWorker.register ("firebase-messaging-sw.js", {scope: "firebase-cloud-messaging-push-scope"})

with relative path

Does anyone know how can I do it so I do not have to do it by hand?
Reply all
Reply to author
Forward
0 new messages