Avena Webapp API - v0.0.1
    Preparing search index...

    Function connect

    • Connects to central NATS over WebSocket and creates a KV manager.

      Tries each URL from buildServerCandidates in order and returns the first connection that succeeds. TLS is turned off explicitly for ws: URLs. Every failure is logged to the console, and the function resolves to null instead of rejecting.

      The KV manager's JetStream client skips the JetStream account check (checkAPI: false), which would otherwise cost one extra round trip each time a bucket is opened. An account without JetStream then fails on the first KV request instead of on open.

      Parameters

      • serverName: string

        Server text as typed, e.g. nats1.oats:8080. A missing scheme is filled in from the page protocol, and the other scheme is tried next.

      • OptionalcredentialsContent: string

        Contents of a .creds file, not a path. Omit to connect without credentials.

      Returns Promise<NatsService | null>

      The connected service, or null if the server text is blank, the credentials authenticator cannot be built, or no candidate URL connects.

      const nats = await connect("nats1.oats:8080", credsText);
      if (!nats) throw new Error("Could not reach central NATS");