-
Notifications
You must be signed in to change notification settings - Fork 162
Description
Proposed change
It currently isnt possible to use nats.js in Cloudflare workers due to some missing nodejs modules. Specifically fs and dns (at least from what I found - there could be more)
It appears that fs is only used if you specify TLS certs in the connection. But it doesn't appear to be possible to bypass dns.
In a conversation in Slack, a team member said that an option could be added to bypass dns resolution.
Additionally, he said that changes to/related to nuid.ts might be needed.
Use case
It would be great to be able to use NATS with Cloudflare Workers, so that connections could be made to NATS servers from the largest edge network.
One use case (among surely infinite) would be to use your NATS Jetstream KV instead of Cloudflare Workers KV, which has up to a 60 second propagation delay for KV writes while NATS KV is "immediately consistent".
I could also see use cases such as wanting to create a NATS connection from CF Workers, rather than directly from a browser client.
In fact, it would be SUPER cool if we could connect from, say, a browser to a CF Worker, which then opens and maintains a connection to a NATS server and subscribes to subjects/streams or watches KV changes. Then any changes could be returned to the browser via, say, an SSE keepalive connection. This would avoid the browser having to do anything with NATS, and could also make use of the CF worker to do any heavy processing prior and just returning, say, HTML to the browser.
It is perhaps possible that nats.ws could already be used with CF workers, but surely it makes most sense to use the native protocol.
More generally, Cloudflare's mission (I've seen it stated somewhere) seems to be to be a sort of operating system for the global internet. An integration with NATS, which makes it so simple to integrate different backend services, seems like a natural fit. Cloudflare could be the front-end/gateway to connect to a NATS-based backend infrastructure.
Contribution
I doubt I could provide much code, but would be happy to help test it if needed.