Permalink
Browse files

Step 16.8: Create server side fcm service

  • Loading branch information...
darkbasic committed Jun 8, 2017
1 parent 17e7fa8 commit e4b66ad69e9bc8cf88eab6c557c5ddb070d71989
Showing with 30 additions and 0 deletions.
  1. +30 −0 api/server/services/fcm.ts
View
@@ -0,0 +1,30 @@
import fetch from 'node-fetch';
export interface FcmNotification {
title: string;
text: string;
}
export class FcmService {
private key: string = Meteor.settings.private.fcm.key;
sendNotification(notification: FcmNotification, destination: string) {
const body = {
notification: notification,
to: destination
};
const options = {
method: 'POST',
body: JSON.stringify(body),
headers: {
"Content-Type": "application/json",
Authorization: `key=${this.key}`
},
};
return fetch("https://fcm.googleapis.com/fcm/send", options);
}
}
export const fcmService = new FcmService();

0 comments on commit e4b66ad

Please sign in to comment.