After following a tutorial to set up an express server for accessing a MongoDB instance on Google Cloud Platform, I encountered an issue when deploying my Firebase functions. When I run the command
firebase deploy --only functions
All functions deploy successfully except for the mongoServer
function, resulting in the error message:
functions: the following filters were specified but do not match any functions in the project: mongoServer
This situation is perplexing considering the steps outlined in the tutorial.
What could be causing this problem?
Here is a snippet from my functions/index.ts
file:
import * as admin from 'firebase-admin';
import * as functions from 'firebase-functions';
import { mongoApp } from './mongo/mongo-server';
import { onSendNotification } from './notifications/send-notification';
import { onImageSave } from './resize-image/onImageSave';
admin.initializeApp();
export const onFileChange = functions.storage.object().onFinalize(onImageSave);
export const sendNotification = functions.https.onRequest(onSendNotification);
export const mongoServer = functions.https.onRequest(mongoApp); // encountering deployment failure here
And here is the essential part of my mongo-server.ts
file:
import * as bodyParser from 'body-parser';
import * as express from 'express';
import * as mongoose from 'mongoose';
import { apiFoods } from './foods.api';
import { Mongo_URI, SECRET_KEY } from './mongo-config';
const path = require('path');
export const mongoApp = express();
mongoApp.set('port', (process.env.PORT || 8090));
mongoApp.use(bodyParser.json());
mongoApp.use(bodyParser.urlencoded({ extended: false }));
connect()
.then((connection: mongoose.Connection) => {
connection.db
.on('disconnected', connect)
.once('open', () => {
console.log('Connected to MongoDB');
apiFoods(mongoApp);
mongoApp.listen(mongoApp.get('port'), () => {
console.log('Listening on port ' + mongoApp.get('port'));
});
});
}).catch(console.log)
function connect(): Promise<mongoose.Connection> {
return mongoose
.connect(Mongo_URI)
.then((goose) => { return goose.connection })
.catch(err => {
console.log(err)
return null;
});
}