Run a web socket on Cloud Functions for Firebase?

2020-01-29 01:20发布

Hello I actually have a REST api running on Cloud Functions for Firebase using http request, but now I need to sync the data on real time requesting to the functions. I read something about web sockets.

Is there a way to run a web socket on Cloud Functions for Firebase?

1条回答
趁早两清
2楼-- · 2020-01-29 02:03

This is not going to be a good fit for Cloud Functions. Websockets rely on long-lived connections to the same server over time; Cloud Functions are ephemeral compute instances that are spun down when there's no traffic. There's no way to force or guarantee that a Cloud Function will keep running or hold a connection open indefinitely.

I would encourage you to investigate using the Firebase Realtime Database as a conduit here instead of trying to add realtime to Cloud Functions.

查看更多
登录 后发表回答