My cloud function is structured like this:
// const {onSchedule} = require("firebase-functions/v2/scheduler"); // The Cloud Functions for Firebase SDK to set up triggers and logging.
import * as logger from "firebase-functions/logger";
const {onRequest} = require('firebase-functions/v2/https');
exports.dailyShiftNotification = onRequest(async (req, res) => {
const promise = fetch(`http://localhost:3000/api/messaging/dailyShiftNotification`, {
method: 'POST',
}).then(res => {
if (!res.ok) {
logger.error("There was an error sending messages");
return res.status(500).send('Error sending messages');
}
return res.json();
}).then(result => {
return result;
});
try {
const result = await promise;
console.log(result);
return res.status(200).send('Messages sent!');
} catch (error) {
console.error('Error:', error);
return res.status(500).send('Error sending messages');
}
});
I'm encountering an issue where I can't return a response from my function, getting an error stating
this expression is not callable. Type 'Number' has no call signatures
I've attempted to address this by using
import { Request, Response } from 'express';
and setting res: Response, req: Request
but it hasn't resolved the problem. Even after installing node-fetch
and trying //ts-ignore
, the function still times out without sending a response.