Skip to content

Commit

Permalink
feat: 푸쉬 이벤트를 수신하는 서비스 워커 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
bbearcookie committed Nov 16, 2023
1 parent f0150e8 commit f36f3f2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
27 changes: 27 additions & 0 deletions public/firebase-messaging-sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
self.addEventListener('install', function (e) {
console.log('[FCM] Service Worker Installed.');
self.skipWaiting();
});

self.addEventListener('activate', function (e) {
console.log('[FCM] Service Worker Activated.');
});

self.addEventListener('push', function (e) {
const data = e.data.json();

if (!data) {
return;
}

console.log('[FCM] Push Received.');

const title = data.notification.title;

const options = {
icon: data.notification.image,
...data.notification
};

self.registration.showNotification(title, options);
});
1 change: 1 addition & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default defineConfig({
VitePWA({
registerType: 'autoUpdate',
injectRegister: 'auto',
filename: 'firebase-messaging-sw.js',
devOptions: {
enabled: false,
type: 'module'
Expand Down

0 comments on commit f36f3f2

Please sign in to comment.