Skip to content

Commit d7b3d39

Browse files
committed
fix FCM sw scripts imports
1 parent 12eee6c commit d7b3d39

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ export default function nuxtFire(moduleOptions) {
8484
),
8585
options: {
8686
firebaseVersion: '7.3.0',
87-
messagingSenderId: options.config[options.currentEnv].messagingSenderId
87+
messagingSenderId: options.config[options.currentEnv].messagingSenderId,
88+
onFirebaseHosting: false
8889
}
8990
})
9091
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nuxt-fire",
3-
"version": "2.4.2",
3+
"version": "2.4.3",
44
"license": "MIT",
55
"description": "Intergrate Firebase into your Nuxt project.",
66
"main": "index.js",

templates/firebase-messaging-sw.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
const options = <%= serialize(options) %>
22
const version = options.firebaseVersion
33
const messagingSenderId = options.messagingSenderId
4+
const onFirebaseHosting = options.onFirebaseHosting
45

5-
// Get ENV && set messagingSenderId
6-
if (this.location.hostname === 'localhost') {
6+
if (onFirebaseHosting) {
7+
// Only works on Firebase hosting!
8+
importScripts('/__/firebase/' + version + '/firebase-app.js')
9+
importScripts('/__/firebase/' + version + '/firebase-messaging.js')
10+
importScripts('/__/firebase/init.js')
11+
}
12+
else {
713
importScripts(
814
'https://www.gstatic.com/firebasejs/' + version + '/firebase-app.js'
915
)
@@ -13,13 +19,7 @@ if (this.location.hostname === 'localhost') {
1319
firebase.initializeApp({
1420
messagingSenderId: messagingSenderId
1521
})
16-
} else {
17-
// Only works on Firebase hosting!
18-
// other option, add PRD messagingSenderId = '337088779183' and do the same
19-
importScripts('/__/firebase/' + version + '/firebase-app.js')
20-
importScripts('/__/firebase/' + version + '/firebase-messaging.js')
21-
importScripts('/__/firebase/init.js')
22-
}
22+
}
2323

2424
// Retrieve an instance of Firebase Messaging so that it can handle background
2525
// messages.

0 commit comments

Comments
 (0)