From d7b3d39e0705600c5dbe14b83706b39914fff08f Mon Sep 17 00:00:00 2001 From: Pascal Date: Mon, 11 Nov 2019 22:58:05 +0800 Subject: [PATCH] fix FCM sw scripts imports --- index.js | 3 ++- package.json | 2 +- templates/firebase-messaging-sw.js | 18 +++++++++--------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 199054bb..cf5061f2 100644 --- a/index.js +++ b/index.js @@ -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 } }) } diff --git a/package.json b/package.json index 3ed036ce..5b856bb3 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/templates/firebase-messaging-sw.js b/templates/firebase-messaging-sw.js index bebdb17f..1fabe51a 100644 --- a/templates/firebase-messaging-sw.js +++ b/templates/firebase-messaging-sw.js @@ -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' ) @@ -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.