Skip to content

Commit e4b66ad

Browse files
committed
Step 16.8: Create server side fcm service
1 parent 17e7fa8 commit e4b66ad

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

api/server/services/fcm.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import fetch from 'node-fetch';
2+
3+
export interface FcmNotification {
4+
title: string;
5+
text: string;
6+
}
7+
8+
export class FcmService {
9+
private key: string = Meteor.settings.private.fcm.key;
10+
11+
sendNotification(notification: FcmNotification, destination: string) {
12+
const body = {
13+
notification: notification,
14+
to: destination
15+
};
16+
17+
const options = {
18+
method: 'POST',
19+
body: JSON.stringify(body),
20+
headers: {
21+
"Content-Type": "application/json",
22+
Authorization: `key=${this.key}`
23+
},
24+
};
25+
26+
return fetch("https://fcm.googleapis.com/fcm/send", options);
27+
}
28+
}
29+
30+
export const fcmService = new FcmService();

0 commit comments

Comments
 (0)