【问题标题】:Firebase Cloud Function Keep return "Request failed with status code 404"Firebase Cloud Function Keep 返回“请求失败,状态码 404”
【发布时间】:2021-07-09 02:29:34
【问题描述】:

我在 firebase 云函数中创建了一些函数,但它们都是有效的。但是我有一个无法正常工作的新功能。我不知道为什么,但我认为它与其他人的模式相同。

这是我的代码:

const functions = require('firebase-functions');
const appVideo = express();
const cors = require('cors')({ origin: true });


appVideo.use(cors);

appVideo.get('/update-video', async(req, res) => {
  console.log('updateStatusVideo idCourse', req.query.idCourse, ' idMateri: ', req.query.idMateri, ' idVideo:', req.query.idVideo);

  res.status(200).send('Oke')
})

exports.video = functions.https.onRequest(appVideo)

我经常将部分部署称为 firebase deploy --only functions:video。但是当我通过浏览器执行 https 函数时,它通常会返回

请求失败,状态码 404

其他奇怪的事情是当我检查浏览器并切换到控制台时,我发现

加载资源失败:服务器响应状态为500()

这是firebase中函数的url:

https://us-central1-my-apps.cloudfunctions.net/video [已修改为机密]

请帮忙

【问题讨论】:

  • 您是否尝试访问https://us-central1-PROJECT_ID.cloudfunctions.net/video/update-video?
  • 请编辑问题以明确您尝试运行此功能的具体方式。问题应该包含足够的细节,任何人都可以重现你观察到的行为。在不知道 URL 的情况下,我们甚至不知道您是否正确指定了它。
  • @samthecodingman 是的
  • @DougStevenson 这是我在 firebase 中注册的函数:https://us-central1-my-apps.cloudfunctions.net/video
  • @samthecodingman 但我的 Firebase 中的网址是 https://us-central1-my-apps.cloudfunctions.net/video

标签: node.js firebase google-cloud-functions


【解决方案1】:

当你导出这一行时:

exports.video = functions.https.onRequest(appVideo);

您定义了一个名为 video 的云函数,该函数部署为 https://us-central1-PROJECT_ID.cloudfunctions.net/video,其中 PROJECT_ID 是您的 Firebase 项目 ID。

因为您为此导出函数使用了express 应用程序,所以处理的任何 URL 必须首先以 https://us-central1-PROJECT_ID.cloudfunctions.net/video(BASE_URL)开头。

这一行:

appVideo.get('/update-video', ...)

将侦听器附加到BASE_URL/update-video,变为https://us-central1-PROJECT_ID.cloudfunctions.net/video/update-video。

如果您只想按原样使用https://us-central1-PROJECT_ID.cloudfunctions.net/video,则需要更改为使用

appVideo.get('/', ...)

如果您只想使用https://us-central1-PROJECT_ID.cloudfunctions.net/update-video,则需要更改为使用

appVideo.get('/', ...)

和

exports.update = {};
exports.update.video = functions.https.onRequest(appVideo);
// "update.video" is deployed as "update-video"

注意:最后一部分滥用deploying groups 来获取所需的URL

【讨论】:

猜你喜欢
  • 2021-04-09
  • 2020-09-18
  • 2021-04-10
  • 2019-10-12
  • 2023-01-21
  • 1970-01-01
  • 1970-01-01
  • 2016-02-21
  • 2020-04-05
相关资源
最近更新 更多