Home > front end >  How to implement FCM with heroku backend app
How to implement FCM with heroku backend app

Time:07-20

I need to send FCM push notification from a chrome extension. I've implemented at the moment the chrome.gcm api that is the easiest way to get FCM working and I'm able to get a registration token and get incoming notifications sended from the FCM console.

Since I need to use the server key into the POST requests to the fcm endpoint to send messages, I want to setup a simple heroku backend as an alternative to cloud functions.

at the moment I have this POST request in my client code, but I'm using it only for dev the chrome extension

            axios.post('https://fcm.googleapis.com/fcm/send', {
                to: 'APA91bELmJY8xTU...',
                notification: {
                    title: 'Test notification',
                    body: 'Some cool text payload'
                }
            }, {
                headers: {
                    'Authorization': 'key=AAAA6C5BuxA:...',
                    'Content-Type': 'application/json'
                }
            }).then( (res) => {
                console.log(res)
            })

Into the production version I want to move this code to the heroku app.

Is possible to use firebase-functions npm package on heroku or I need to setup an express app with an endpoint?

I've found this buildpack but I'm not sure if it will give me the ability to write my heroku nodejs code like a cloud function

functions.https.onRequest( (req, res) => { ... })

CodePudding user response:

Is possible to use firebase-functions npm package on heroku?

The firebase-functions package is the glue between Google Cloud Functions and your (server-side) Firebase code. There is no simple way to use it on a Heroku instance.

Setting up a custom Express endpoint sounds like the more idiomatic approach here.

  • Related