Hi,
I am trying to subscribe/fetch updating data from a nats server and to build a realtime API for my frontend app.
I’ve been struggling with ExpressJs for a while and I started to try Resgate today.
I followed the Helloworld example and wrote the following code:
nc.subscribe('pkt', function(msg){ // subscribe updating pkt data
console.log(msg.length, msg); // check if empty
if(msg.length>0){ // serve data
nc.subscribe('get.pkt', (req, reply) => {
nc.publish(reply, JSON.stringify({ result: { model: JSON.parse(msg)}}));
});
nc.subscribe('access.pkt', (req, reply) => {
nc.publish(reply, JSON.stringify({ result: { get: true }}));
});
}
})
In my console, I can see the msg gets updated frequently but the API (http://localhost:8080/api/pkt) only returns the first msg subscribed.
I am not too sure how to fix this issue.
Any help would be greatly appreciated:)