Skip to content

Commit

Permalink
fix FCM sw scripts imports
Browse files Browse the repository at this point in the history
  • Loading branch information
lupas committed Nov 11, 2019
1 parent 12eee6c commit d7b3d39
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ export default function nuxtFire(moduleOptions) {
),
options: {
firebaseVersion: '7.3.0',
messagingSenderId: options.config[options.currentEnv].messagingSenderId
messagingSenderId: options.config[options.currentEnv].messagingSenderId,
onFirebaseHosting: false
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nuxt-fire",
"version": "2.4.2",
"version": "2.4.3",
"license": "MIT",
"description": "Intergrate Firebase into your Nuxt project.",
"main": "index.js",
Expand Down
18 changes: 9 additions & 9 deletions templates/firebase-messaging-sw.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
const options = <%= serialize(options) %>
const version = options.firebaseVersion
const messagingSenderId = options.messagingSenderId
const onFirebaseHosting = options.onFirebaseHosting

// Get ENV && set messagingSenderId
if (this.location.hostname === 'localhost') {
if (onFirebaseHosting) {
// Only works on Firebase hosting!
importScripts('/__/firebase/' + version + '/firebase-app.js')
importScripts('/__/firebase/' + version + '/firebase-messaging.js')
importScripts('/__/firebase/init.js')
}
else {
importScripts(
'https://www.gstatic.com/firebasejs/' + version + '/firebase-app.js'
)
Expand All @@ -13,13 +19,7 @@ if (this.location.hostname === 'localhost') {
firebase.initializeApp({
messagingSenderId: messagingSenderId
})
} else {
// Only works on Firebase hosting!
// other option, add PRD messagingSenderId = '337088779183' and do the same
importScripts('/__/firebase/' + version + '/firebase-app.js')
importScripts('/__/firebase/' + version + '/firebase-messaging.js')
importScripts('/__/firebase/init.js')
}
}

// Retrieve an instance of Firebase Messaging so that it can handle background
// messages.
Expand Down

0 comments on commit d7b3d39

Please sign in to comment.