Google Cloud 功能需要一个 PORT 来监听

问题描述 投票:0回答:1

我正在编写一个云函数来简单地获取 oauth 令牌并将其写入 firebase。我的代码可以正常工作,直到我包含

import * as admin from 'firebase-admin';

admin.initializeApp();

我将

"firebase-admin": "^9.8.0"
包含在对
package.json
的依赖中。

添加上面的代码后,我在部署时遇到错误:

Could not create or update Cloud Run service oauthhandling2, Container Healthcheck failed. 
Revision 'oauthhandling2-00012-wim' is not ready and cannot serve traffic. The user-provided 
container failed to start and listen on the port defined provided by the PORT=8080 
environment variable. Logs for this revision might contain more information.

不确定这是否有意义,因为我所在的函数应该通过 https 调用触发,而不是监听端口。另外,如果我不使用 firebase-admin,它也可以工作。 有什么想法吗?我相信,我不应该被要求提供一个端口来监听,因为它是云功能,并且是通过 https 调用触发的。

function cloud
1个回答
0
投票

您可能正在使用 Gen1 Function。在 Cloud Functions Gen 2 中,函数本质上是在 Cloud Run 上运行,这要求容器侦听 PORT 环境变量以获取 HTTP 请求。这是与第 1 代的转变,第 1 代直接调用函数,无需侦听特定端口。

© www.soinside.com 2019 - 2024. All rights reserved.