Skip to content

Commit

Permalink
fix : firebase-messaging-sw.js 파일의 중요정보를 다른 파일에서 불러오는식으로 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheol-Jin committed Jan 9, 2025
1 parent 3d5d679 commit 5b595fe
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/main/resources/static/firebase-messaging-sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
importScripts('https://www.gstatic.com/firebasejs/9.17.1/firebase-app-compat.js');
importScripts('https://www.gstatic.com/firebasejs/9.17.1/firebase-messaging-compat.js');

fetch('/firebase-config.json')
.then(response => response.json())
.then(config => {
firebase.initializeApp(config);

const messaging = firebase.messaging();

// 백그라운드 메시지 처리
messaging.onBackgroundMessage((payload) => {
console.log('[firebase-messaging-sw.js] 백그라운드 메시지 수신:', payload);

const notificationTitle = payload.notification.title;
const notificationOptions = {
body: payload.notification.body,
icon: payload.notification.icon || '/default-icon.png' // 아이콘 경로 설정
};

self.registration.showNotification(notificationTitle, notificationOptions);
});
})
.catch(error => {
console.error('Firebase 설정 로드 실패:', error);
});

0 comments on commit 5b595fe

Please sign in to comment.