I want implement server side events in appwrite. For implementing server side event I need a server which supports this. In express server I can do this by res.write(). But in appwrite function I can't do this as it supports on res.send and res.json. Is there any way to achieve SSE in appwrite function?
You want to be able to send events from an Appwrite function? Or you want your Appwrite function to act as a server?
Can you elaborate more about your use case?
My requirement is my appwrite function generate random numbers for 10 senconds and I want to send these random numbers to all the active users.
I want to send randomly generated numbers in real time.
this appwrite function runs once in an hour
Mmm You can try workaround like so.
Function
- Create some Appwrite function.
- When trigger make the function generate 10 random numbers.
- Insert the numbers into a collection
Realtime
- Create Realtime channel
- subscribe to the channel of the with the previous collection.
Now you'll have a realtime event that will broadcast to all of the subscriptions with 10 random numbers.
OK. this could be done.
How to achieve Appwrite function to act as a server?
In what way?
That you can access it directly?
Appwrite function runs on which server?
To what part you mean?
Appwrite function are scale-to-zero cloud functions.
If I use nodeJS for writing appwrite fuction, does it use express server or http server
That mean, you can deploy your functions to your Appwrite instance (self-hosted or cloud) Then, access your function using one of the available SDKs.
Got you
It uses micro
server,
You can find more about it here
https://github.com/open-runtimes/open-runtimes/blob/main/runtimes/node-14.5/server.js
Appwrite uses micro
behind the scenes. But, this part is hidden from you.
So, when developing a service using Appwrite function you can't develop it with a full backend mindset, But, think of it as a direct endpoint in which you're executing your code.
That mean, you can't have routes for your function.
But - it's common - to create logical routes.
So you can add a variable to data you're sending to the function, Let say action
Then inside the function you can check action
value and act according to that value.
That will give a logical route.
Cool... Thank you for your time and response
[SOLVED] Implementing Server-Side Events in appwrite function.
Recommended threads
- Need help with createExecution function
Hi, Need some help understanding createExecution. When requesting function execution via createExecution, the function handler arguments are incorrect and rese...
- custom domain with CloudFlare
Hi all, it seems that CloudFlare has blocked cross-domain CNAME link which made my app hostname which is in CloudFlare, unable to create a CNAME pointing to clo...
- My organization's project is blocked
My organization's project is blocked so unblocked my organization then I will this