mirror of
https://github.com/appy-one/acebase-client.git
synced 2026-05-24 22:01:18 -06:00
[GH-ISSUE #18] Run query from cloud function / serverless function? Disable websocket? #15
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/acebase-client#15
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @qpwo on GitHub (Jan 27, 2022).
Original GitHub issue: https://github.com/appy-one/acebase-client/issues/18
Originally assigned to: @appy-one on GitHub.
I am trying to get acebase-client to work in a serverless function. Do you have a recommended way to do this, or do you recommend against it?
The below snippet works fine in the browser and in straight node, but not in my local development version of next.js's/vercel's serverless function API thing:
Specifically,
db.ready()never completes and I get a bunch ofWebsocket connection error: Error: websocket error.I tried
network: { transports: ['polling'] },andsync: { timing: 'manual' },in thenew AceBaseClient, but neither seemed to help. I also tested if anaxios.get()from within a cloud function worked (in case it was some kind of CORS problem) and it executed fine.@appy-one commented on GitHub (Jan 28, 2022):
Vercel serverless functions don't support websocket connections. See https://vercel.com/support/articles/do-vercel-serverless-functions-support-websocket-connections .
I'll look at implementing a switch that disables the websocket connection. Doing so would disable getting real-time notifications, but still allow you to query and update the db. Would that be a solution for you?
@qpwo commented on GitHub (Feb 3, 2022):
Yes! That's exactly what I'm looking for!
@qpwo commented on GitHub (Feb 3, 2022):
I think it could also be useful for low-bandwidth / intermittent connections and scripts or CLI tools, where you may just want a quick query
@qpwo commented on GitHub (Feb 8, 2022):
How challenging do you think this would be? I may be able to help some, although not very quickly
@appy-one commented on GitHub (Feb 8, 2022):
I'm afraid it's not a very simple procedure but I will definitely look into it
@appy-one commented on GitHub (Mar 29, 2022):
I've added a
realtimenetwork setting that allows disabling the websocket connection and only use the REST API.Can you try updating acebase-client to v1.12.0, then add
network: { realtime: false }to your client settings. This will cause a ping to the server every 60 seconds to allow connection state to keep working, You can disable that too with themonitorsetting, but that will probably cause issues as I haven't tested that combination yet.Full example:
Let me know if that works!
@appy-one commented on GitHub (Apr 29, 2022):
I'm closing this for now, let me know if this is working. Feel free to reopen if not.