Hello,
I followed all the steps in the video no 15 (https://www.youtube.com/watch?v=pnysHgQvOiM&list=PLk7v1Z2rk4hjM2NPKqtWQ_ndCuoqUj5Hh&index=16&t=0s) but I'm getting
"404
Page Not Found
The specified file was not found on this website. Please check the URL for mistakes and try again.
Why am I seeing this?
This page was generated by the Firebase Command-Line Interface. To modify it, edit the 404.html file in your project's configured public directory." in Postman.
Till 15th video, everything is working fine. REST API is working fine on localhost but it's not working with the web address of the google function. Please check the code
Please help me with this issue, I'll be highly grateful to you.
index.js
const functions = require('firebase-functions');
var {google} = require('googleapis')
var MESSAGING_SCOPE = "https://www.googleapis.com/auth/firebase.messaging"
var SCOPES = [MESSAGING_SCOPE]
var express = require('express')
var app = express();
var bodyParser = require('body-parser');
var router = express.Router();
var request = require('request');
app.use(bodyParser.urlencoded({extended:true}));
app.use(bodyParser.json());
router.post('/send',function(req,res){
getAccessToken().then(function(access_token){
var title = req.body.title;
var body = req.body.body;
var token = req.body.token;
request.post({
headers:{
Authorization: 'Bearer '+ access_token
}, url: "https://fcm.googleapis.com/v1/projects/androidnotification-e44a6/messages:send",
body: JSON.stringify(
{
"message":{
"token" : token,
"notification" : {
"body" : body,
"title" : title
}
}
}
)
},function(error,reponse,body){
res.end(body);
console.log(body);
});
});
});
app.use('/api',router);
function getAccessToken()
{
return new Promise(function(resolve,reject){
var key= require("./service-account.json");
var jwtClient = new google.auth.JWT(
key.client_email,
null,
key.private_key,
SCOPES,
null
);
jwtClient.authorize(function(error,tokens){
if(error)
{
reject(error)
}
resolve(tokens.access_token)
});
jwtClient.authorize(function(error,tokens){
if(error)
{
reject(error)
}
resolve(tokens.access_token)
console.log(tokens.access_token)
});
});
}
exports.api = functions.https.onRequest(app);
firebase.json
{
"hosting":
{
"public": "public",
"rewrites": [
{
"source": "/api/send",
"functions": "api"
}
],
"ignore": [
"firebase.json",
"/.*",
"/node_modules/**"
]