首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过防火墙云函数部署服务器

如何通过防火墙云函数部署服务器
EN

Stack Overflow用户
提问于 2018-06-19 02:56:45
回答 1查看 295关注 0票数 0

我跟踪了一个基本实例来设置一个快速服务器来访问一个托管在google平台上的mongo实例。但是当我运行命令

firebase deploy --only functions

除了mongoServer函数之外,我的所有函数都被部署,并且我得到了错误:

函数:指定了以下筛选器,但与项目中的任何函数不匹配: mongoServer

奇怪的是基本实例

我做错什么了?

这是我的functions/index.ts

代码语言:javascript
复制
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文件:

代码语言:javascript
复制
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;
    });
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-19 04:21:10

您不能将快速应用程序部署到管理自己连接的云函数中。(直接使用快递并不是你所举的“基本例子”的一部分)。使用express所能做的就是设置路由,并允许云函数向这些路由发送请求。云函数直接管理自己的所有传入连接。

有关更基本的内容,请参见这个例子,其中涉及表达式。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50920004

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档