Closed qpwo closed 2 years ago
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?
Yes! That's exactly what I'm looking for!
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
How challenging do you think this would be? I may be able to help some, although not very quickly
I'm afraid it's not a very simple procedure but I will definitely look into it
I've added a realtime
network 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 the monitor
setting, but that will probably cause issues as I haven't tested that combination yet.
Full example:
const db = new AceBaseClient({ dbname: 'mydb', host: 'localhost', port: 1352, network: { realtime: false, monitor: true, interval: 60 })
Let me know if that works!
I'm closing this for now, let me know if this is working. Feel free to reopen if not.
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.