【发布时间】:2020-10-07 18:09:13
【问题描述】:
我正在尝试将我的 express 服务器部署到 firebase 功能。当我尝试使用“firebase serve”命令运行它时,它运行良好,但是当我部署它时,我无法访问我的服务器的任何路由。
我的函数/index.js:
const functions = require('firebase-functions')
const express = require('express')
const app = express()
const bodyParser = require('body-parser')
const controller = require('./controller')
const cors = require('cors')
app.use(cors({ origin: true }))
app.use(bodyParser.json())
app.use(express.json())
app.get('/getGardens', controller.getGardens)
app.post('/getPresentDogsInGarden', controller.getPresentDogsInGarden)
exports.App = functions.https.onRequest(app)
firebase.json:
{
"hosting": {
"public": "public",
"rewrites" : [{"source" : "**", "function" : "App"}]
}
}
我的链接:...whatever/App/getGardens
得到响应:'错误:无法处理请求'
编辑:
解决了我的问题。代码和初始化一切正常。 我不知道的是,通过免费的 spark 计划,我无法使用不属于 google 的 API。我在我的控制器模块中使用了 mongo,但它无法连接。我升级到了 blaze plan,它运行良好。
【问题讨论】:
-
Firebase 函数控制台中的确切错误是什么?
标签: javascript node.js firebase express google-cloud-functions