[GH-ISSUE #18] Run query from cloud function / serverless function? Disable websocket? #15

Closed
opened 2026-05-23 08:34:10 -06:00 by gitea-mirror · 7 comments
Owner

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:

const db = new AceBaseClient({
    host: 'localhost',
    port: 5757,
    dbname: 'mydb',
    https: false,
})
await db.ready()
await db.auth.signIn('admin', 'coolpassword')
await db.ref('counter').transaction(snap => snap.val() + 1 )
console.log('final value:' ,(await db.ref('counter').get()).val())

Specifically, db.ready() never completes and I get a bunch of Websocket connection error: Error: websocket error.

I tried network: { transports: ['polling'] }, and sync: { timing: 'manual' }, in the new AceBaseClient, but neither seemed to help. I also tested if an axios.get() from within a cloud function worked (in case it was some kind of CORS problem) and it executed fine.

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: ```ts const db = new AceBaseClient({ host: 'localhost', port: 5757, dbname: 'mydb', https: false, }) await db.ready() await db.auth.signIn('admin', 'coolpassword') await db.ref('counter').transaction(snap => snap.val() + 1 ) console.log('final value:' ,(await db.ref('counter').get()).val()) ``` Specifically, `db.ready()` never completes and I get a bunch of `Websocket connection error: Error: websocket error`. I tried `network: { transports: ['polling'] },` and `sync: { timing: 'manual' },` in the `new AceBaseClient`, but neither seemed to help. I also tested if an `axios.get()` from within a cloud function worked (in case it was some kind of CORS problem) and it executed fine.
gitea-mirror 2026-05-23 08:34:10 -06:00
Author
Owner

@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?

<!-- gh-comment-id:1023934197 --> @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?
Author
Owner

@qpwo commented on GitHub (Feb 3, 2022):

Yes! That's exactly what I'm looking for!

<!-- gh-comment-id:1029412053 --> @qpwo commented on GitHub (Feb 3, 2022): Yes! That's exactly what I'm looking for!
Author
Owner

@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

<!-- gh-comment-id:1029435612 --> @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
Author
Owner

@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

<!-- gh-comment-id:1033000868 --> @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
Author
Owner

@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

<!-- gh-comment-id:1033027256 --> @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
Author
Owner

@appy-one commented on GitHub (Mar 29, 2022):

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!

<!-- gh-comment-id:1081768405 --> @appy-one commented on GitHub (Mar 29, 2022): 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: ```js const db = new AceBaseClient({ dbname: 'mydb', host: 'localhost', port: 1352, network: { realtime: false, monitor: true, interval: 60 }) ``` Let me know if that works!
Author
Owner

@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.

<!-- gh-comment-id:1113631602 --> @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.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/acebase-client#15
No description provided.