Replies: 7 comments 1 reply
-
|
Did you get an answer on this? |
Beta Was this translation helpful? Give feedback.
-
|
I can only speak to Firestore, but in theory, an HTTP proxy should work just fine. You don't need to use the complicated Service Worker setup though, as the Firestore SDK can be configured to connect to a specific host instead of |
Beta Was this translation helpful? Give feedback.
-
|
@trullock my original question was submitted in the context where my firebase web app couldn't be used by Chinese users because they couldn't visit firebase urls. The question was submitted 3+ years ago, so I don't know what's the current api. In my 3yo firebase 9.x codebase, this worked, to some extent: const db = initializeFirestore(app, {
host: myReverseProxyUrl, // I thought if the proxy can only do http, then onSnapshot listeners must use long poll (?) because by default it uses websocket (?)
experimentalAutoDetectLongPolling: true, // I think this is true by default nowadays
// experimentalForceLongPolling: true, // maybe set to true if you're sure you'll always need to use an http proxy
});But I did end up using a service worker, because it's more powerful. I needed to reroute more things than just firestore, for instance "callable functions". (Nowadays I don't know if cloud functions are still in fashion, because ideally you should use a meta framework to put your front and backend code under the same package.json so they can share typings) I ended up using service worker to reroute |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for your responses. I'm actaully trying to instrument Reads and was hoping to intercept http/ws traffic to insert some logging. I can't see how onSnapshot actually fetches data, I'm getting results but I don't see any WS traffic via chrome debug tools... I'll have a poke around the clues above. Thanks very much |
Beta Was this translation helpful? Give feedback.
-
|
FYI Firstore does not use websockets for onSnapshot. Instead, it uses a Google-proprietary protocol called "WebChannel" (https://google.github.io/closure-library/api/goog.net.WebChannel.html). |
Beta Was this translation helpful? Give feedback.
-
|
What are WebChannels underneath then, just long polling? |
Beta Was this translation helpful? Give feedback.
-
|
Long polling is part of it. The low-level details of WebChannel are out of scope for the Firebase repository (and my personal knowledge) but Copilot may be able to answer your low-level questions about the protocol. Here's an example conversation I just tested out with Copilot by clicking the "Chat With Copilot" button at https://github.com/google/closure-library: https://gist.github.com/dconeybe/2d9d46e36f1b17768147d2d7e35e5634 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I use the firestore js sdk in my web app, and faced a problem: some of my users are behind a firewall that blocks firebase urls (
https://firebase.googleapis.com/,https://firestore.googleapis.com/, etc ) that the sdk talks to.I plan to solve it by adding a service worker to intercept all requests to these urls, and forward them to my own server, which will then pass the requests to the firebase urls, then pass back the responses.
I imagine it could work, but I'm not sure if onSnapshot listeners will work too. I don't know the mechanism of the onSnapshot listeners, but I imagine WebSockets or gRPC are involved, but when I look at the devTools, I didn't see any WebSockets or gRPC traffic when I trigger the listener.
In any case, I want to know if my service worker + reverse proxy approach would work. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions