我正在尝试将firebase连接到我的React项目以实现推送通知,这是我的firebase.js文件:
import firebase from "firebase";
const firebaseConfig = {
apiKey: "API_KEY",
authDomain: "AUTH_DOMAIN",
databaseURL: "DATABASE_URL",
projectId: "PROJECT_ID",
storageBucket: "STORAGE",
messagingSenderId: "MSGID",
appId: "APPID",
measurementId: "MEASUREID"
};
firebase.initializeApp(firebaseConfig);
export default firebase;
这是我的firebase-messaging-sw.js文件:
const { registration } = require("../src/Components/loginPage/Reducers/RegistrationReducer");
importScripts('https://www.gstatic.com/firebasejs/7.16.1/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/7.16.1/firebase-messaging.js');
firebase.initializeApp({
messagingSenderId: "1061462994754",
})
const initMessaging = firebase.messaging().useServiceWorker(registration)
我想要做的是将Firebase部署到服务器上的子目录,而她的修改方式是修改firebase.json以使其正常工作:
{
"hosting": {
"public": "public",
"headers": [
{
"source": "/serviceWorker.js",
"headers": [
{
"key": "Cache-Control",
"value": "no-cache"
}
]
}
],
"redirects": [
{
"source": "/frontend/saif/**", // The subdirectory on the server
"destination": "https://testing-server.com/",
"type": 302
}
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
],
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
我认为我需要将我的子目录添加到/firebase-messaging-sw.js之前的请求URL中,这可能可以解决此问题,但是我不确定。有什么帮助吗?