This respository serves as a sample implementation for sending push notifications via the Firebase Messaging HTTP v1 interface.
Firebase is dropping support for their legacy interface effective Jul 20, 2024, so any application using that older interface will be forced to migrate.
Firebase has the document, Migrate from legacy FCM APIs to HTTP v1,
and while useful, it only contains code snippets and not full working examples.
I had initially intended to use the V1 interface directly from within my NativeScript app, but I simply encountered too many obstacles. (This issue documents my ordeals.) I pivoted to instead use a Node.js server via my ISP, which required becoming more familiar with both Node.js and cpanel. This approach, too, encountered many obstacles. (See this SO post.)
I finally tried using Firebase Hosting, and this works quite well. There's some setup involved, and I'll describe that below. I offer this repository for those who will be following in my footsteps to save them some of the considerable time and effort this took.
There are good resources that document how to set up a Node.js app hosted on Firebase. I recommend these to get started:
If you followed the steps from the above tutorial you should already have the folder structure set up on your local machine. Copy index.js
and package.json
from the /features
folder of this respository into your own /features
folder. CD into the /features
folder and run npm install
to install the necessary dependencies.
Inspect the source files index.js
and client.js
and edit both files accordingly.
client.js
is independent and does not need to be located in the /features
folder, but it will work from there.
This sample implementation is designed to work for multiple Firebase apps, with each having its service account JSON file downloaded into the /keys
folder.
Adjust the design to suit your needs.
The sample app will not run as-is.
You will need to edit client.js
appropriately for your needs, as indicated by the //TODO:
comments therein.
You'll also need to have .firebase.rc
and firebase.json
files in place.
These get created automatically in the setup process described in the tutorial (resource #1, above).
With all that ready, first test the app locally:
CD
into the/features
folder- Run
npm run serve
- When the local server is active, run
node client --local
To run the app from Firebase:
- Run
npm run deploy
- When the deployment completes, run
node client
In the end, the code needed to migrate to the HTTP v1 interface is fairly simple, but it took me some 80 hours to get from start to finish. If you're confronted with this same migration effort, I wish you Godspeed and hope this sample implementation will help.
David Cole Jan 5, 2025