我跟踪了一个基本实例来设置一个快速服务器来访问一个托管在google平台上的mongo实例。但是当我运行命令
firebase deploy --only functions
除了mongoServer函数之外,我的所有函数都被部署,并且我得到了错误:
函数:指定了以下筛选器,但与项目中的任何函数不匹配: mongoServer
奇怪的是基本实例
我做错什么了?
这是我的functions/index.ts
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); // this one fails下面是我的(剥离的) mongo-server.ts文件:
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;
});
}发布于 2018-06-19 04:21:10
您不能将快速应用程序部署到管理自己连接的云函数中。(直接使用快递并不是你所举的“基本例子”的一部分)。使用express所能做的就是设置路由,并允许云函数向这些路由发送请求。云函数直接管理自己的所有传入连接。
有关更基本的内容,请参见这个例子,其中涉及表达式。
https://stackoverflow.com/questions/50920004
复制相似问题